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
30pub mod location_generator;
31/// Module providing writers that can automatically roll over to new files based on size thresholds.
32pub mod rolling_writer;
33
34type DefaultOutput = Vec<DataFileBuilder>;
35
36/// File writer builder trait.
37pub trait FileWriterBuilder<O = DefaultOutput>: Send + Clone + 'static {
38    /// The associated file writer type.
39    type R: FileWriter<O>;
40    /// Build file writer.
41    fn build(self) -> impl Future<Output = Result<Self::R>> + Send;
42}
43
44/// File writer focus on writing record batch to different physical file format.(Such as parquet. orc)
45pub trait FileWriter<O = DefaultOutput>: Send + CurrentFileStatus + 'static {
46    /// Write record batch to file.
47    fn write(&mut self, batch: &RecordBatch) -> impl Future<Output = Result<()>> + Send;
48    /// Close file writer.
49    fn close(self) -> impl Future<Output = Result<O>> + Send;
50}