gabotechs commented on code in PR #157:
URL: 
https://github.com/apache/datafusion-iceberg/pull/157#discussion_r4783008167


##########
crates/datafusion/src/write/commit.rs:
##########
@@ -146,757 +95,285 @@ impl DisplayAs for IcebergCommitExec {
                     .map(|field| field.to_string().trim_end().to_string())
                     .collect::<Vec<_>>()
                     .join(", ");
-                write!(
-                    f,
-                    "IcebergCommitExec: table={}, schema=[{fields}]",
-                    self.table.identifier()
-                )
-            }
-            DisplayFormatType::TreeRender => {
-                write!(f, "IcebergCommitExec: table={}", 
self.table.identifier())
+                write!(f, "IcebergCommitSink(table={table}, 
schema=[{fields}])")
             }
         }
     }
 }
 
-impl ExecutionPlan for IcebergCommitExec {
-    fn name(&self) -> &str {
-        "IcebergCommitExec"
-    }
-
-    fn properties(&self) -> &Arc<PlanProperties> {
-        &self.plan_properties
-    }
-
-    fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
-        vec![&self.input]
-    }
-
-    fn apply_expressions(
-        &self,
-        _f: &mut dyn FnMut(&Arc<dyn PhysicalExpr>) -> 
Result<TreeNodeRecursion>,
-    ) -> Result<TreeNodeRecursion> {
-        Ok(TreeNodeRecursion::Continue)
+#[async_trait]
+impl DataSink for IcebergCommitSink {
+    fn schema(&self) -> &ArrowSchemaRef {
+        &self.schema
     }
 
-    fn required_input_distribution(
+    async fn write_all(

Review Comment:
   A multi-partition input now commits only partition 0 and silently drops the 
rest.
   
   `IcebergCommitExec::execute` used to reject an input with more than one 
partition, but that check and `rejects_multiple_input_partitions` were removed. 
`DataSinkExec::execute` doesn't replace it, since it only runs input partition 
0. Could we keep an explicit error for this case, or at least keep a test that 
pins the behavior?
   
   1. Build `DataSinkExec::new(write_with_4_partitions, 
Arc::new(IcebergCommitSink::new(..)), None)` without a `CoalescePartitionsExec`.
   2. Call `execute(0)`.
   3. Only partition 0's data files are committed; the other files are orphaned 
and the count is too low, with no error.



##########
crates/datafusion/src/write/commit.rs:
##########
@@ -18,120 +18,69 @@
 use std::fmt::{Debug, Formatter};
 use std::sync::Arc;
 
-use datafusion::arrow::array::{
-    Array, ArrayRef, LargeBinaryArray, RecordBatch, UInt64Array,
-};
-use datafusion::arrow::datatypes::{
-    DataType, Field, Schema as ArrowSchema, SchemaRef as ArrowSchemaRef,
-};
-use datafusion::common::{
-    exec_err, internal_datafusion_err, internal_err, 
tree_node::TreeNodeRecursion,
-};
-use datafusion::error::{DataFusionError, Result};
+use async_trait::async_trait;
+use datafusion::arrow::array::AsArray;
+use datafusion::arrow::datatypes::SchemaRef as ArrowSchemaRef;
+use datafusion::common::{exec_datafusion_err, exec_err};
+use datafusion::datasource::sink::DataSink;
+use datafusion::error::Result;
 use datafusion::execution::{SendableRecordBatchStream, TaskContext};
-use datafusion::physical_expr::{EquivalenceProperties, Partitioning, 
PhysicalExpr};
-use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType};
-use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
-use datafusion::physical_plan::{
-    DisplayAs, DisplayFormatType, ExecutionPlan, PlanProperties,
-};
+use datafusion::physical_plan::{DisplayAs, DisplayFormatType};
 use futures::StreamExt;
 use iceberg::Catalog;
 use iceberg::spec::{DataFile, read_data_files_from_avro};
 use iceberg::table::Table;
 use iceberg::transaction::{ApplyTransactionAction, Transaction};
 
+use super::IcebergWriteExec;
 use super::exec::DATA_FILES_COL_NAME;
 use crate::to_datafusion_error;
 
-/// IcebergCommitExec is responsible for collecting the files written and use
-/// [`Transaction::fast_append`] to commit the data files written.
+/// Commits the data files an [`IcebergWriteExec`] wrote, in one
+/// [`Transaction::fast_append`].
 ///
-/// Its input produces the data files to commit, in the form
-/// [`IcebergWriteExec`](super::IcebergWriteExec) outputs them, in a single
-/// partition. Its output is one row holding the number of rows committed.
+/// Run it in a [`DataSinkExec`] over the write. The `DataSinkExec` outputs one
+/// row holding the number of rows committed. It reads only partition 0 of its
+/// input, so the write must be coalesced to one partition with a
+/// [`CoalescePartitionsExec`]; the physical optimizer adds one when it is

Review Comment:
   The optimizer only adds the `CoalescePartitionsExec` when the plan goes 
through `EnforceDistribution`.
   
   Callers that build, rebuild or deserialize the plan by hand (e.g. 
distributed engines on workers) will read this as a guarantee and skip the 
coalesce. I'd state the single-partition input as a hard requirement.



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

Reply via email to