parquet/record/record_writer.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use crate::schema::types::TypePtr;
6
7use super::super::errors::ParquetError;
8use super::super::file::writer::SerializedRowGroupWriter;
9
10/// Trait describing how to write a record (the implementer) to a row group writer.
11///
12/// [`parquet_derive`] crate provides a derive macro [`ParquetRecordWriter`] for this trait
13/// for unnested structs.
14///
15/// The type parameter `T` is used to work around the rust orphan rule
16/// when implementing on types such as `&[T]`.
17///
18/// [`parquet_derive`]: https://crates.io/crates/parquet_derive
19/// [`ParquetRecordWriter`]: https://docs.rs/parquet_derive/53.0.0/parquet_derive/derive.ParquetRecordWriter.html
20pub trait RecordWriter<T> {
21 /// Writes from `self` into `row_group_writer`.
22 fn write_to_row_group<W: std::io::Write + Send>(
23 &self,
24 row_group_writer: &mut SerializedRowGroupWriter<W>,
25 ) -> Result<(), ParquetError>;
26
27 /// Generated schema used by `row_group_writer`
28 fn schema(&self) -> Result<TypePtr, ParquetError>;
29}