alexanderbianchi opened a new pull request, #160:
URL: https://github.com/apache/datafusion-iceberg/pull/160

   Follow-up to #159 for the write-distribution item in #23. The Apache PR 
targets `main` because #159's branch lives on a fork. [Review just the feature 
commit](https://github.com/alexanderbianchi/datafusion-iceberg-upstream/compare/4f15b6a7ba1b74b9bae4c85b5523088317ec2fdc...13146068fb6e21423aa83c719cb1409d419eb3d4).
   
   ## Change
   
   A partitioned Iceberg table can opt in with the table property 
`write.distribution-mode=hash`. `IcebergWriteExec` declares 
`KeyPartitioned([_partition])` on its input. DataFusion can then plan a hash 
exchange or use a suitable existing distribution. The key is the full Iceberg 
partition tuple, including bucket, time, truncate, and multi-field specs.
   
   Clustered writers still request a local sort. Fanout writers can consume the 
grouped input unsorted. With the property unset, with another mode, or on an 
unpartitioned table, the writer accepts its input’s existing distribution.
   
   ## Observed file layout
   
   Two input tasks each produce a row for both keys of a table partitioned by 
`truncate(10, cat)`.
   
   | Input task | Values of `cat` |
   | --- | --- |
   | A | 11, 21 |
   | B | 19, 29 |
   
   On #159, the insert produced four one-row files even with the property set. 
With this change, the committed snapshot contains one file for key `10` and one 
for key `20`, each with two rows.
   
   ## Spark compatibility
   
   **Full compatibility with Spark’s adaptive write distribution would require 
native DataFusion support for both coalescing small post-shuffle partitions and 
splitting oversized ones across writer tasks based on observed shuffle bytes.** 
Spark’s Iceberg writer declares a flexible distribution and an advisory size, 
and Spark AQE can adjust the shuffle as it runs. Here `KeyPartitioned` sends 
every row for a hot Iceberg key to one writer task. The existing coalesce 
before the commit gathers file descriptors after the files have already been 
written. [Iceberg’s Spark write 
contract](https://github.com/apache/iceberg/blob/56c11c953d28c0547a058635babebefddfc26dcb/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/SparkWrite.java#L153-L176)
 · [Spark AQE coalescing and skew 
splitting](https://spark.apache.org/docs/4.0.2/sql-performance-tuning.html#coalescing-post-shuffle-partitions)
   
   ## Verification
   
   `cargo test --locked -p iceberg-datafusion --test integration 
insert_into::hash_distributes` runs the committed-file example and a 
single-input fanout write. The tests inspect the plans that executed and the 
truncated keys and record counts of the committed files.
   
   `cargo fmt --all -- --check`, `cargo clippy --workspace --locked 
--all-targets -- -D warnings`, and `cargo test --workspace --locked` passed.
   


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