CTTY commented on code in PR #1769: URL: https://github.com/apache/iceberg-rust/pull/1769#discussion_r2449627437
########## crates/iceberg/src/writer/partitioning/unpartitioned_writer.rs: ########## @@ -0,0 +1,443 @@ +// 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 provides the `UnpartitionedWriter` implementation. + +use std::marker::PhantomData; + +use crate::Result; +use crate::spec::PartitionKey; +use crate::writer::partitioning::PartitioningWriter; +use crate::writer::{DefaultInput, DefaultOutput, IcebergWriter, IcebergWriterBuilder}; + +/// A writer that adapts `IcebergWriterBuilder` to the `PartitioningWriter` interface +/// for non-partitioned tables. +/// +/// This writer ignores partition keys and writes all data to a single underlying writer. +/// It lazily creates the writer on the first write operation. +/// +/// # Type Parameters +/// +/// * `B` - The inner writer builder type +/// * `I` - Input type (defaults to `RecordBatch`) +/// * `O` - Output collection type (defaults to `Vec<DataFile>`) +pub struct UnpartitionedWriter<B, I = DefaultInput, O = DefaultOutput> +where + B: IcebergWriterBuilder<I, O>, + O: IntoIterator + FromIterator<<O as IntoIterator>::Item>, + <O as IntoIterator>::Item: Clone, +{ + inner_builder: B, + writer: Option<B::R>, + output: Vec<<O as IntoIterator>::Item>, + _phantom: PhantomData<I>, +} + +impl<B, I, O> UnpartitionedWriter<B, I, O> +where + B: IcebergWriterBuilder<I, O>, + I: Send + 'static, + O: IntoIterator + FromIterator<<O as IntoIterator>::Item>, + <O as IntoIterator>::Item: Send + Clone, +{ + /// Create a new `UnpartitionedWriter`. + pub fn new(inner_builder: B) -> Self { + Self { + inner_builder, + writer: None, + output: Vec::new(), + _phantom: PhantomData, + } + } +} + +#[async_trait::async_trait] +impl<B, I, O> PartitioningWriter<I, O> for UnpartitionedWriter<B, I, O> Review Comment: Thinking out loud: Implementing `PartitioningWriter` for `UnpartitionedWriter` allows user to build their own partitioning writer rather than using a fanout_mode flag, but 1. This feels a bit weird, `UnpartitionedWriter` can be an independent wrapper of `IcebergWriter` that don't have to implement any trait. 2. To make the change mentioned above, `TaskWriter` should take `IcebergWriterBuilder` and `fanout_mode` flag, so the type of `PartitioningWriter` can be determined 3. Maybe `PartitioningWriter` can be an enum rather than a trait? After making changes above, `PartitioningWriter` won't be used like a trait at all. This is trival tho. 4. Naming is hard, and I hate the name `PartitioningWriter` more everyday 🫤 . Initially I was thinking of "partitioning-aware" writer but now `PartitioningWriter::write` always takes a `PartitionKey`, making `PartitionedWriter` sounds more reasonable and it just ryhmes with `UnpartitionedWriter` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
