iceberg/writer/partitioning/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Partitioning writers for handling partitioned Iceberg tables.
19//!
20//! This module provides two strategies for writing to partitioned tables:
21//! - [`FanoutWriter`](fanout_writer::FanoutWriter): Handles unsorted data by maintaining multiple active writers
22//! - [`ClusteredWriter`](clustered_writer::ClusteredWriter): Optimized for pre-sorted data with single active writer
23
24pub mod clustered_writer;
25pub mod fanout_writer;
26pub mod unpartitioned_writer;
27
28use crate::Result;
29use crate::spec::PartitionKey;
30use crate::writer::{DefaultInput, DefaultOutput};
31
32/// A writer that can write data to partitioned tables.
33///
34/// This trait provides methods for writing data with partition keys and
35/// closing the writer to retrieve the output.
36#[async_trait::async_trait]
37pub trait PartitioningWriter<I = DefaultInput, O = DefaultOutput>: Send + 'static {
38    /// Write data with a partition key.
39    ///
40    /// # Parameters
41    ///
42    /// * `partition_key` - Partition key to determine which partition to write to
43    /// * `input` - The input data to write
44    ///
45    /// # Returns
46    ///
47    /// `Ok(())` on success, or an error if the write operation fails.
48    async fn write(&mut self, partition_key: PartitionKey, input: I) -> Result<()>;
49
50    /// Close the writer and return the output.
51    ///
52    /// # Returns
53    ///
54    /// The accumulated output from all write operations.
55    async fn close(self) -> Result<O>;
56}