Repository navigation
refactor: tidy sort_by_partition - #133
Closed
NoahKusaba wants to merge 1 commit into
Closed
NoahKusaba wants to merge 1 commit into
NoahKusaba wants to merge 1 commit into
Conversation
NoahKusaba
force-pushed
the
refactor/sort-by-partition
branch
from
November 21, 2026 13:31
c2cb36f to
6375a90
Compare
Contributor
Author
|
Starting to cleanup the insert related code, as all other read related work has an open PR. |
NoahKusaba
marked this pull request as ready for review
November 21, 2026 13:42
Shorten its docs, build the LexOrdering with From instead of handling a LexOrdering::new error that can't happen, and replace tests that executed DataFusion's sort with snapshots of the plan and the error.
NoahKusaba
force-pushed
the
refactor/sort-by-partition
branch
from
November 21, 2026 13:53
6375a90 to
ea2b4d5
Compare
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?
N/A. Refactor; no behavior change.
Rationale for this change
When
write.datafusion.fanout.enabledis false,insert_intocallssort_by_partitionso the clustered writer gets its input grouped by partition. The function only looks up the_partitioncolumn and wraps the input in aSortExecthat keeps its partitions. The code around that is noisier than it needs to be:# Argumentsand# Returnssections, for apub(crate)function with one argument.SortOptions::default(), // Ascending, nulls lastis incorrect: Arrow's default puts nulls first.LexOrdering::newreturnsNoneonly for an empty list, and it's always given one expression.preserve_partitioning.What changes are included in this PR?
LexOrderingis built withLexOrdering::from([PhysicalSortExpr::new_default(..)]), removing the unreachable error branch. These are the same calls as before:new_defaultisPhysicalSortExpr::new(expr, SortOptions::default()), andFrom<[PhysicalSortExpr; N]>callsLexOrdering::new. It takes a fixed-size array, which can't be empty, so it has noNonecase to handle.test_sort_by_partition_sorts_each_partitionsnapshots the plan:SortExec: expr=[_partition@1 ASC], preserve_partitioning=[true]. The old tests ran on a single partition, so they never checkedpreserve_partitioning, which the clustered writer depends on.test_sort_by_partition_requires_partition_columnsnapshots the full error, instead of checking that it contains a substring.The column lookup and the error message are unchanged. The new plan snapshot prints the sort options (
ASChere; other options would show asDESCorNULLS LAST), and both new tests pass unchanged against the implementation onmain.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