fix: use build_join_schema for CrossJoinExec output schema metadata#23485
Open
gmhelmold wants to merge 1 commit into
Open
fix: use build_join_schema for CrossJoinExec output schema metadata#23485gmhelmold wants to merge 1 commit into
gmhelmold wants to merge 1 commit into
Conversation
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?
Closes #23434.
Rationale for this change
An aggregate over a pure cross join of two tables that carry the same schema-metadata key with different values fails at planning time:
The logical plan builds a cross join as
Join { join_type: Inner, .. }(LogicalPlanBuilder::cross_join), so its schema comes frombuild_join_schema, which merges input metadata left-wins.CrossJoinExec::new, however, merged metadata inline with anextend, which is right-wins. The two schemas therefore disagree on any conflicting metadata key, and the physical-vs-logical schema check rejects the plan.CrossJoinExecis the only join operator that still hand-rolled its output schema.HashJoinExec,NestedLoopJoinExec,SortMergeJoinExec,SymmetricHashJoinExecand the piecewise merge join all already build their schema viabuild_join_schema. This aligns cross join with that precedent, in the same family as the union-metadata consistency fix #21127.What changes are included in this PR?
CrossJoinExec::newnow derives its output schema frombuild_join_schema(&left.schema(), &right.schema(), &JoinType::Inner)instead of the inline field-chain + right-wins metadataextend. The field list (left-then-right, no induced nullability — Inner setsforce_nullable = false) is unchanged; only the metadata-merge order changes to left-wins, matching the logical schema.test_cross_join_metadata) mirroringjoins::utils::test_join_metadata.cross_join_with_conflicting_schema_metadata) reproducing the exact failure from CrossJoinExec merges schema metadata inconsistently with the logical plan #23434.Are these changes tested?
Yes. Both tests fail on
mainwith the errors quoted above and pass with the fix. The e2e's inputs (2-row left, 1-row right) also drive theJoinSelectionswap path, exercisingswap_inputs.Are there any user-facing changes?
Yes — a bug fix. The output schema metadata of a cross join now follows left-wins on conflicting keys (consistent with the logical plan and with every other join operator). Field names, types, nullability and column order are unchanged. Aggregations over cross joins of metadata-carrying tables that previously errored now plan and execute.