|
| 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 | +//! Task writer module for high-level Iceberg table writing operations. |
| 19 | +//! |
| 20 | +//! This module provides the [`TaskWriter`] trait and [`BaseTaskWriter`] implementation |
| 21 | +//! for writing data to Iceberg tables with automatic partition handling. |
| 22 | +
|
| 23 | +use crate::Result; |
| 24 | +use crate::writer::{DefaultInput, DefaultOutput}; |
| 25 | + |
| 26 | +/// High-level async trait for writing tasks to Iceberg tables. |
| 27 | +/// |
| 28 | +/// The `TaskWriter` trait provides a simplified interface for writing data and retrieving |
| 29 | +/// results, abstracting away the complexity of partition handling and writer selection. |
| 30 | +/// |
| 31 | +/// # Type Parameters |
| 32 | +/// |
| 33 | +/// * `I` - Input type (defaults to `DefaultInput` which is `RecordBatch`) |
| 34 | +/// * `O` - Output type (defaults to `DefaultOutput` which is `Vec<DataFile>`) |
| 35 | +#[async_trait::async_trait] |
| 36 | +pub trait TaskWriter<I = DefaultInput, O = DefaultOutput>: Send + 'static { |
| 37 | + /// Write input data to the task writer. |
| 38 | + /// |
| 39 | + /// # Arguments |
| 40 | + /// |
| 41 | + /// * `input` - The input data to write |
| 42 | + /// |
| 43 | + /// # Returns |
| 44 | + /// |
| 45 | + /// Returns `Ok(())` on success, or an error if the write operation fails. |
| 46 | + async fn write(&mut self, input: I) -> Result<()>; |
| 47 | + |
| 48 | + /// Close the writer and return the accumulated output. |
| 49 | + /// |
| 50 | + /// # Returns |
| 51 | + /// |
| 52 | + /// Returns the accumulated output (e.g., `Vec<DataFile>`) on success, |
| 53 | + /// or an error if the close operation fails. |
| 54 | + async fn close(self) -> Result<O>; |
| 55 | +} |
0 commit comments