ZENOTME commented on code in PR #275: URL: https://github.com/apache/iceberg-rust/pull/275#discussion_r1533228766
########## 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: I find that this will cause more complexity for the interface. The necessary fields for writer can't be store in the builder because a builder can used to build multiple writers so it means that the fields should be pass when we create the writer. So we need interface like following so that we can pass different config. ``` pub trait IcebergWriterBuilder<I = DefaultInput, O = DefaultOutput>: Send + Clone + 'static { /// The associated writer type. type R: IcebergWriter<I, O>; type C; /// Build the iceberg writer. async fn build(self,config: Self::C) -> Result<Self::R>; } ``` This interface can let us create the writer in a more flexible way but incurs more complexity. So I'm concerned is that worth.🤔 -- 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