ZENOTME commented on code in PR #703: URL: https://github.com/apache/iceberg-rust/pull/703#discussion_r1850434941
########## crates/iceberg/src/writer/base_writer/equality_delete_writer.rs: ########## @@ -0,0 +1,544 @@ +// 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 `EqualityDeleteWriter`. + +use std::sync::Arc; + +use arrow_array::{ArrayRef, RecordBatch, StructArray}; +use arrow_schema::{DataType, FieldRef, Fields, Schema, SchemaRef}; +use itertools::Itertools; + +use crate::spec::{DataFile, Struct}; +use crate::writer::file_writer::{FileWriter, FileWriterBuilder}; +use crate::writer::{IcebergWriter, IcebergWriterBuilder}; +use crate::{Error, ErrorKind, Result}; + +/// Builder for `EqualityDeleteWriter`. +#[derive(Clone)] +pub struct EqualityDeleteFileWriterBuilder<B: FileWriterBuilder> { + inner: B, +} + +impl<B: FileWriterBuilder> EqualityDeleteFileWriterBuilder<B> { + /// Create a new `EqualityDeleteFileWriterBuilder` using a `FileWriterBuilder`. + pub fn new(inner: B) -> Self { + Self { inner } + } +} + +/// Config for `EqualityDeleteWriter`. +pub struct EqualityDeleteWriterConfig { + equality_ids: Vec<usize>, + projector: ArrowFieldProjector, + partition_value: Struct, +} + +impl EqualityDeleteWriterConfig { + /// Create a new `DataFileWriterConfig` with equality ids. + pub fn new( + equality_ids: Vec<usize>, + projector: ArrowFieldProjector, + partition_value: Option<Struct>, + ) -> Self { + Self { + equality_ids, + projector, + partition_value: partition_value.unwrap_or(Struct::empty()), + } + } +} + +#[async_trait::async_trait] +impl<B: FileWriterBuilder> IcebergWriterBuilder for EqualityDeleteFileWriterBuilder<B> { + type R = EqualityDeleteFileWriter<B>; + type C = EqualityDeleteWriterConfig; + + async fn build(self, config: Self::C) -> Result<Self::R> { + Ok(EqualityDeleteFileWriter { + inner_writer: Some(self.inner.clone().build().await?), + projector: config.projector, + equality_ids: config.equality_ids, + partition_value: config.partition_value, + }) + } +} + +/// A writer write data +pub struct EqualityDeleteFileWriter<B: FileWriterBuilder> { + inner_writer: Option<B::R>, Review Comment: `fn close(self)` of file writer need the owenership. So we need to using option here is to take out the writer when we call close. Same thing happened in data file writer. https://github.com/apache/iceberg-rust/blob/697a20060f2247da87f73073e8bf5ab407bd40ea/crates/iceberg/src/writer/base_writer/data_file_writer.rs#L81 Maybe workaround is make `fn close(self)` of file writer to `fn close(&mut self)`, but same thing will happen in file writer. We need to wrap parquet writer in Option. But the benefit is we can hide it in lower layer. https://github.com/apache/iceberg-rust/blob/697a20060f2247da87f73073e8bf5ab407bd40ea/crates/iceberg/src/writer/file_writer/parquet_writer.rs#L410 -- 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