liurenjie1024 commented on code in PR #704: URL: https://github.com/apache/iceberg-rust/pull/704#discussion_r1976816015
########## crates/iceberg/src/writer/base_writer/position_delete_file_writer.rs: ########## @@ -0,0 +1,277 @@ +// 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. + +//! Position delete file writer. +use std::future::Future; +use std::pin::Pin; +use std::sync::Arc; + +use arrow_array::builder::{PrimitiveBuilder, StringBuilder}; +use arrow_array::types::Int64Type; +use arrow_array::RecordBatch; +use once_cell::sync::Lazy; + +use crate::arrow::schema_to_arrow_schema; +use crate::spec::{DataContentType, DataFile, NestedField, PrimitiveType, Schema, Struct, Type}; +use crate::writer::file_writer::{FileWriter, FileWriterBuilder}; +use crate::writer::{IcebergWriter, IcebergWriterBuilder}; +use crate::{Error, ErrorKind, Result}; + +const POS_DELETE_FIELD1_NAME: &str = "file_path"; +const POS_DELETE_FIELD1_ID: i32 = 2147483546; +const POS_DELETE_FIELD2_NAME: &str = "pos"; +const POS_DELETE_FIELD2_ID: i32 = 2147483545; +static POSITION_DELETE_SCHEMA: Lazy<Schema> = Lazy::new(|| { + Schema::builder() + .with_fields(vec![ + Arc::new(NestedField::required( + POS_DELETE_FIELD1_ID, + POS_DELETE_FIELD1_NAME, + Type::Primitive(PrimitiveType::String), + )), + Arc::new(NestedField::required( + POS_DELETE_FIELD2_ID, + POS_DELETE_FIELD2_NAME, + Type::Primitive(PrimitiveType::Long), + )), + ]) + .build() + .unwrap() +}); + +/// Position delete input. +#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Debug)] +pub struct PositionDeleteInput<'a> { + /// The path of the file. + pub path: &'a str, + /// The row number in data file + pub pos: i64, +} + +impl<'a> PositionDeleteInput<'a> { + /// Create a new `PositionDeleteInput`. + pub fn new(path: &'a str, row: i64) -> Self { + Self { path, pos: row } + } +} +/// Builder for `MemoryPositionDeleteWriter`. +#[derive(Clone)] +pub struct PositionDeleteWriterBuilder<B: FileWriterBuilder> { + inner: B, + partition_value: Option<Struct>, +} + +impl<B: FileWriterBuilder> PositionDeleteWriterBuilder<B> { + /// Create a new `MemoryPositionDeleteWriterBuilder` using a `FileWriterBuilder`. + pub fn new(inner: B, partition_value: Option<Struct>) -> Self { + Self { + inner, + partition_value, + } + } +} + +#[async_trait::async_trait] +impl<'a, B: FileWriterBuilder> IcebergWriterBuilder<Vec<PositionDeleteInput<'a>>> + for PositionDeleteWriterBuilder<B> +{ + type R = PositionDeleteWriter<B>; + + async fn build(self) -> Result<Self::R> { + Ok(PositionDeleteWriter { + inner_writer: Some(self.inner.build().await?), + partition_value: self.partition_value.unwrap_or(Struct::empty()), + }) + } +} + +/// Position delete writer. +pub struct PositionDeleteWriter<B: FileWriterBuilder> { + inner_writer: Option<B::R>, + partition_value: Struct, +} + +impl<'a, B: FileWriterBuilder> IcebergWriter<Vec<PositionDeleteInput<'a>>> Review Comment: Sounds reasonable to me, user is free to choose how to buffer outside. -- 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