iceberg/writer/file_writer/
mod.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
18//! This module contains the writer for data file format supported by iceberg: parquet, orc.
19
20use arrow_array::RecordBatch;
21use futures::Future;
22
23use super::CurrentFileStatus;
24use crate::Result;
25use crate::spec::DataFileBuilder;
26
27mod parquet_writer;
28pub use parquet_writer::{ParquetWriter, ParquetWriterBuilder};
29
30use crate::io::OutputFile;
31
32pub mod location_generator;
33/// Module providing writers that can automatically roll over to new files based on size thresholds.
34pub mod rolling_writer;
35
36type DefaultOutput = Vec<DataFileBuilder>;
37
38/// File writer builder trait.
39pub trait FileWriterBuilder<O = DefaultOutput>: Clone + Send + Sync + 'static {
40    /// The associated file writer type.
41    type R: FileWriter<O>;
42    /// Build file writer.
43    fn build(&self, output_file: OutputFile) -> impl Future<Output = Result<Self::R>> + Send;
44}
45
46/// File writer focus on writing record batch to different physical file format.(Such as parquet. orc)
47pub trait FileWriter<O = DefaultOutput>: Send + CurrentFileStatus + 'static {
48    /// Write record batch to file.
49    fn write(&mut self, batch: &RecordBatch) -> impl Future<Output = Result<()>> + Send;
50    /// Close file writer.
51    fn close(self) -> impl Future<Output = Result<O>> + Send;
52}