parquet/record/
record_writer.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::schema::types::TypePtr;
19
20use super::super::errors::ParquetError;
21use super::super::file::writer::SerializedRowGroupWriter;
22
23/// Trait describing how to write a record (the implementator) to a row group writer.
24///
25/// [`parquet_derive`] crate provides a derive macro [`ParquetRecordWriter`] for this trait
26/// for unnested structs.
27///
28/// The type parameter `T` is used to work around the rust orphan rule
29/// when implementing on types such as `&[T]`.
30///
31/// [`parquet_derive`]: https://crates.io/crates/parquet_derive
32/// [`ParquetRecordWriter`]: https://docs.rs/parquet_derive/53.0.0/parquet_derive/derive.ParquetRecordWriter.html
33pub trait RecordWriter<T> {
34    /// Writes from `self` into `row_group_writer`.
35    fn write_to_row_group<W: std::io::Write + Send>(
36        &self,
37        row_group_writer: &mut SerializedRowGroupWriter<W>,
38    ) -> Result<(), ParquetError>;
39
40    /// Generated schema used by `row_group_writer`
41    fn schema(&self) -> Result<TypePtr, ParquetError>;
42}