fix: Preserve metadata when nl-join is swapped#23759
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn test_swapped_cross_join_schema_on_conflicting_metadata() { |
There was a problem hiding this comment.
This moved into test_swap_joins_on_conflicting_metadata
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23759 +/- ##
==========================================
- Coverage 80.71% 80.71% -0.01%
==========================================
Files 1090 1090
Lines 370370 370380 +10
Branches 370370 370380 +10
==========================================
- Hits 298948 298944 -4
- Misses 53601 53609 +8
- Partials 17821 17827 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
d62b975 to
14c0ea3
Compare
933139d to
385dd94
Compare
|
|
||
| let join = CrossJoinExec::new(input("a", "left value"), input("b", "right value")); | ||
|
|
||
| let swapped_join = join.swap_inputs().unwrap(); |
There was a problem hiding this comment.
This is a internal API from optimizer, it requires strict pre-conditions in order to use it correctly, so I think this should not be called directly.
Probably we could either
- mark raw
swap_inputs()API as unsafe to use directly - Add sanity checks inside to ensure it must be used correctly
- Deprecate it from the public API
I'm wondering is it possible to trigger the bug from only SQL script 🤔 ? If yes this seem like a major bug.
There was a problem hiding this comment.
If swap_inputs is not safe we should definitely mark it thusly
There are some caveats documented here
This function is public so other downstream projects can use it to construct HashJoinExec with right side as the build side.
I do think it is meant to be used publically and the usecase is reasonable in my mind (user control over join order)
If it is hard to use / easy to mess up, perhaps we can find a better API
a278aa6 to
d4b7c77
Compare
|
I tend to think we should let this query error, but we can provide better error message. Here are more details in the original issue, let's continue the discussion here: #23461 (comment) |
Which issue does this PR close?
join_selectionflips schema-level metadata, failing "Schema mismatch" #23461 and resolves it for nl-joins. More joins types have the same issue.Rationale for this change
When a
nl-joinis swapped, the metadata is rebuilt based on the inverted inputs. This can cause a change of metadata when the metadata has conflicting values which results in an error e.g.:Therefore this pr avoids rebuilding the metadata based on the swapped inputs for
nl-joinand uses the original metadata insteadWhat changes are included in this PR?
NestedLoopJoinExecBuilderby ametadatafield to create a newNestedLoopJoinExecwith existing metadataNestedLoopJoinExecBuilderinNestedLoopJoinExec::swap_inputsto swap the input and preserve the metadataAre these changes tested?
Yes
Are there any user-facing changes?
No