Repository navigation
fix: require IcebergWriteExec's input sorted by partition without fanout - #138
Open
NoahKusaba wants to merge 2 commits into
Open
NoahKusaba wants to merge 2 commits into
NoahKusaba wants to merge 2 commits into
Conversation
NoahKusaba
force-pushed
the
fix/write-exec-input-requirements
branch
from
November 22, 2026 18:33
468ec41 to
52a1777
Compare
insert_into added a sort on `_partition` when fanout was disabled, but no node required it, so the physical optimizer removed it and the clustered writer failed on unsorted input. For unpartitioned tables the sort was added anyway and failed at planning, since they have no `_partition` column. IcebergWriteExec now declares the ordering through `required_input_ordering`, only for partitioned tables written without fanout, and the optimizer adds the sort. `write/sort.rs` and the fanout parsing in insert_into are removed, along with the unit tests that inspected the unoptimized plan.
NoahKusaba
force-pushed
the
fix/write-exec-input-requirements
branch
from
November 22, 2026 19:09
52a1777 to
18ac36f
Compare
NoahKusaba
marked this pull request as ready for review
November 22, 2026 19:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
It also fixes the unpartitioned case reported in #43.
Rationale for this change
With
write.datafusion.fanout.enabled=false,insert_intoadded a sort on_partitionbeforeIcebergWriteExec, because the clustered writer needs each task's rows sorted by partition. Nothing in the plan required the sort, so the physical optimizer removed it:Partitioned table: the clustered writer gets unsorted input and the INSERT fails (INSERT into a partitioned table with fanout disabled always fails: the optimizer removes the partition sort #38).
Unpartitioned table: the sort was added whenever fanout was off, but only partitioned tables have a
_partitioncolumn, so the INSERT failed at planning (INSERT into an unpartitioned table fails when fanout is disabled #43):The unit tests didn't catch this because they inspected the plan
insert_intoreturns, before physical optimization.What changes are included in this PR?
IcebergWriteExecimplementsrequired_input_ordering: sorted on_partitionwhen a partitioned table is written without fanout, which is whenTaskWriteruses the clustered writer. The optimizer adds the sort. Unpartitioned tables require none.insert_intono longer parses the fanout property or adds a sort;write/sort.rsis removed, along with the two unit tests that checked the unoptimized plan.IcebergWriteExecrather than as nodes added ininsert_into.The repartition
insert_intoadds has the same problem: the optimizer removes it too. That's a performance issue rather than a failure, so it's left for a follow-up.Are these changes tested?
Yes. Three tests in
tests/insert_into.rsrun anINSERTthrough SQL and snapshot the optimized plan and the rows read back:sorts_partitioned_writes_by_partition_without_fanout:SortExec: expr=[_partition@2 ASC]under the write.writes_partitioned_tables_unsorted_with_fanout: no sort with fanout enabled (the default), replacing the unit test that checked this on the unoptimized plan.inserts_into_an_unpartitioned_table_without_fanout: no sort, and the insert succeeds.The first fails on
mainbecause the optimizer removes the sort, and the third with the planning error above.Larger fanout-disabled inserts into partitioned tables still fail with "The input is not sorted!" until #39 is fixed (#81): the plan is now correct, but the writer splits each batch's partitions in arbitrary order. These tests write a single batch, so they don't depend on it.
Are there any user-facing changes?
INSERTwithwrite.datafusion.fanout.enabled=falsekeeps its partition sort for partitioned tables, and no longer fails at planning for unpartitioned ones.write.datafusion.fanout.enabledvalue is now reported when the write executes rather than at planning, like the other write properties.