Skip to content

Commit a9104dc

Browse files
ZENOTMEZENOTME
and
ZENOTME
authored
feat: init file writer interface (#168)
* init file writer interface * refine --------- Co-authored-by: ZENOTME <[email protected]>
1 parent 1775c90 commit a9104dc

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

crates/iceberg/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ mod scan;
5151
pub mod expr;
5252
pub mod transaction;
5353
pub mod transform;
54+
55+
pub mod writer;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
20+
use super::{CurrentFileStatus, DefaultOutput};
21+
use crate::Result;
22+
use arrow_array::RecordBatch;
23+
use futures::Future;
24+
25+
/// File writer builder trait.
26+
pub trait FileWriterBuilder<O = DefaultOutput>: Send + Clone + 'static {
27+
/// The associated file writer type.
28+
type R: FileWriter<O>;
29+
/// Build file writer.
30+
fn build(self) -> impl Future<Output = Result<Self::R>> + Send;
31+
}
32+
33+
/// File writer focus on writing record batch to different physical file format.(Such as parquet. orc)
34+
pub trait FileWriter<O = DefaultOutput>: Send + CurrentFileStatus + 'static {
35+
/// Write record batch to file.
36+
fn write(&mut self, batch: &RecordBatch) -> impl Future<Output = Result<()>> + Send;
37+
/// Close file writer.
38+
fn close(self) -> impl Future<Output = Result<O>> + Send;
39+
}

crates/iceberg/src/writer/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
//! The iceberg writer module.
19+
20+
use crate::spec::DataFileBuilder;
21+
22+
pub mod file_writer;
23+
24+
type DefaultOutput = Vec<DataFileBuilder>;
25+
26+
/// The current file status of iceberg writer. It implement for the writer which write a single
27+
/// file.
28+
pub trait CurrentFileStatus {
29+
/// Get the current file path.
30+
fn current_file_path(&self) -> String;
31+
/// Get the current file row number.
32+
fn current_row_num(&self) -> usize;
33+
/// Get the current file written size.
34+
fn current_written_size(&self) -> usize;
35+
}

0 commit comments

Comments
 (0)