ZENOTME commented on code in PR #275: URL: https://github.com/apache/iceberg-rust/pull/275#discussion_r1534012662
########## crates/iceberg/src/writer/base_writer/data_file_writer.rs: ########## @@ -0,0 +1,310 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! This module provide `DataFileWriter`. + +use crate::spec::{DataContentType, DataFileBuilder}; +use crate::writer::file_writer::FileWriter; +use crate::writer::CurrentFileStatus; +use crate::writer::{file_writer::FileWriterBuilder, IcebergWriter, IcebergWriterBuilder}; +use crate::Result; +use arrow_array::RecordBatch; +use itertools::Itertools; + +/// Builder for `DataFileWriter`. +#[derive(Clone)] +pub struct DataFileWriterBuilder<B: FileWriterBuilder> { + inner: B, +} + +impl<B: FileWriterBuilder> DataFileWriterBuilder<B> { + /// Create a new `DataFileWriterBuilder` using a `FileWriterBuilder`. + pub fn new(inner: B) -> Self { + Self { inner } + } +} + +#[allow(async_fn_in_trait)] +impl<B: FileWriterBuilder> IcebergWriterBuilder for DataFileWriterBuilder<B> { + type R = DataFileWriter<B>; + + async fn build(self) -> Result<Self::R> { + Ok(DataFileWriter { + inner_writer: self.inner.clone().build().await?, + builder: self.inner, + }) + } +} + +/// A writer write data is within one spec/partition. +pub struct DataFileWriter<B: FileWriterBuilder> { + builder: B, + inner_writer: B::R, +} + +#[async_trait::async_trait] +impl<B: FileWriterBuilder> IcebergWriter for DataFileWriter<B> { + async fn write(&mut self, batch: RecordBatch) -> Result<()> { + self.inner_writer.write(&batch).await + } + + async fn flush(&mut self) -> Result<Vec<DataFileBuilder>> { Review Comment: The partition value may only be known when running. e.g. `PartitionWriterBuilder<DataFileWriterBuilder>`, the partition value is only knowing when partition writer accept the value. And we can't create the DataFileWriter with partition value in advance. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org