ZENOTME commented on code in PR #760:
URL: https://github.com/apache/iceberg-rust/pull/760#discussion_r1877297478


##########
crates/iceberg/src/writer/mod.rs:
##########
@@ -57,30 +59,130 @@ type DefaultInput = RecordBatch;
 type DefaultOutput = Vec<DataFile>;
 
 /// The builder for iceberg writer.
-#[async_trait::async_trait]
 pub trait IcebergWriterBuilder<I = DefaultInput, O = DefaultOutput>:
     Send + Clone + 'static
 {
     /// The associated writer type.
     type R: IcebergWriter<I, O>;
     /// The associated writer config type used to build the writer.
-    type C;
+    type C: Send + 'static;
     /// Build the iceberg writer.
-    async fn build(self, config: Self::C) -> Result<Self::R>;
+    fn build(self, config: Self::C) -> impl Future<Output = Result<Self::R>> + 
Send;
 }
 
 /// The iceberg writer used to write data to iceberg table.
-#[async_trait::async_trait]
 pub trait IcebergWriter<I = DefaultInput, O = DefaultOutput>: Send + 'static {
     /// Write data to iceberg table.
-    async fn write(&mut self, input: I) -> Result<()>;
+    fn write(&mut self, input: I) -> impl Future<Output = Result<()>> + Send + 
'_;
     /// Close the writer and return the written data files.
     /// If close failed, the data written before maybe be lost. User may need 
to recreate the writer and rewrite the data again.
     /// # NOTE
     /// After close, regardless of success or failure, the writer should never 
be used again, otherwise the writer will panic.
-    async fn close(&mut self) -> Result<O>;
+    fn close(&mut self) -> impl Future<Output = Result<O>> + Send + '_;
 }
 
+mod dyn_trait {
+    use dyn_clone::{clone_trait_object, DynClone};
+
+    use super::Result;
+    use crate::writer::{DefaultInput, DefaultOutput, IcebergWriter, 
IcebergWriterBuilder};
+
+    #[async_trait::async_trait]
+    pub trait DynIcebergWriterBuilder<C, I, O>: Send + DynClone + 'static {
+        async fn build(self, config: C) -> Result<BoxedIcebergWriter<I, O>>;
+    }
+
+    clone_trait_object!(<C, I, O> DynIcebergWriterBuilder<C, I, O>);
+
+    #[async_trait::async_trait]
+    impl<I: 'static + Send, O: 'static + Send, B: IcebergWriterBuilder<I, O>>
+        DynIcebergWriterBuilder<B::C, I, O> for B
+    where B::C: Send
+    {
+        async fn build(self, config: B::C) -> Result<BoxedIcebergWriter<I, O>> 
{
+            Ok(self.build(config).await?.boxed())
+        }
+    }
+
+    /// Type alias for `Box<dyn DynIcebergWriterBuilder>`
+    pub type BoxedIcebergWriterBuilder<C, I = DefaultInput, O = DefaultOutput> 
=
+        Box<dyn DynIcebergWriterBuilder<C, I, O>>;
+
+    impl<C: Send + 'static, I: Send + 'static, O: Send + 'static> 
IcebergWriterBuilder<I, O>
+        for BoxedIcebergWriterBuilder<C, I, O>
+    {
+        type R = BoxedIcebergWriter<I, O>;
+        type C = C;
+
+        async fn build(self, config: Self::C) -> Result<Self::R> {
+            DynIcebergWriterBuilder::build(self, config).await

Review Comment:
   Can this function name be dyn_build, similar to DynIcebergWriter? So that 
the name will not be conflict. We can use `self.dyn_build` here.



-- 
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

Reply via email to