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

   ## Which issue does this PR close?
   
   N/A. Refactor; no behavior change.
   
   ## Rationale for this change
   
   `sort_by_partition` is a `pub(crate)` helper that `insert_into` calls when 
`write.datafusion.fanout.enabled` is false. It builds a `SortExec` on the 
`_partition` column, keeping the input's partitions, for the clustered writer. 
The function is about 15 lines, but it carries 14 lines of docs restating its 
signature, a comment on nearly every statement, and an error branch that can't 
be reached. Its tests run DataFusion's sort on in-memory data, so they check 
DataFusion rather than the plan this function builds.
   
   ## What changes are included in this PR?
   
   - The docs say in three lines what the function does and why.
   - The ordering is built with `[PhysicalSortExpr::new_default(..)].into()`. 
`LexOrdering::new` returns `None` only for an empty list, so the old error 
branch couldn't run.
   - Two tests replace three:
     - `test_sort_by_partition_sorts_each_partition` snapshots the plan: 
`SortExec: expr=[_partition@1 ASC], preserve_partitioning=[true]`. The old 
tests ran on a single partition, so they never checked `preserve_partitioning`, 
which the clustered writer depends on.
     - `test_sort_by_partition_requires_partition_column` snapshots the full 
error, instead of checking that it contains a substring.
   
   The column lookup and the error message are unchanged.
   
   ## Are these changes tested?
   
   Yes, by the two tests above. The removed tests checked that rows come out 
sorted, including how Arrow orders struct values. That's DataFusion's and 
Arrow's behavior, and the clustered writer only needs equal partition values 
next to each other.
   
   What this crate does need to check is that a real fanout-disabled INSERT 
keeps the sort through the optimizer and writes correctly. That needs 
end-to-end tests, and the old unit tests couldn't catch it: they passed while 
#38 broke every such INSERT into a partitioned table. Those tests belong with 
the fixes: #132 (unpartitioned tables) and #38 (partitioned tables).
   
   ## Are there any user-facing changes?
   
   No.
   
   ## AI Disclosure
   
   - Used Claude Code to review the write path, make the change and draft this 
description. I reviewed the change.
   


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