-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix logical vs physical schema mismatch for UNION where some inputs are constants #12954
Merged
alamb
merged 6 commits into
apache:main
from
influxdata:12733/metadata-xfer-both-directions
Oct 23, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eef498c
test(12733): reproducer of when metadata from the left side is not tr…
wiedld 0d25c56
fix(12733): because either the left or right fields may be chosen, ad…
wiedld c92b3bd
test(12733): update regression test to show that fix works
wiedld ec9cf2d
Add extra test to fix other issue with schema metadata
itsjunetime b229807
Fix union_schema to merge metadatas for both fields and schema
itsjunetime a8e7c68
fmt
itsjunetime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,34 @@ ORDER BY id, name, l_name; | |
NULL bar NULL | ||
NULL NULL l_bar | ||
|
||
# Regression test: missing field metadata from left side of the union when right side is chosen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I verified that this query fails without the code changes in this PR: External error: query failed: DataFusion error: Schema error: No field named nonnull_name. Valid fields are table_with_metadata.id, table_with_metadata.name, table_with_metadata.l_name.
[SQL] select name from (
SELECT nonnull_name as name FROM "table_with_metadata"
UNION ALL
SELECT NULL::string as name
) group by name order by name;
at test_files/metadata.slt:127
Error: Execution("1 failures")
error: test failed, to rerun pass `-p datafusion-sqllogictest --test sqllogictests` |
||
query T | ||
select name from ( | ||
SELECT nonnull_name as name FROM "table_with_metadata" | ||
UNION ALL | ||
SELECT NULL::string as name | ||
) group by name order by name; | ||
---- | ||
no_bar | ||
no_baz | ||
no_foo | ||
NULL | ||
|
||
# Regression test: missing schema metadata from union when schema with metadata isn't the first one | ||
# and also ensure it works fine with multiple unions | ||
query T | ||
select name from ( | ||
SELECT NULL::string as name | ||
UNION ALL | ||
SELECT nonnull_name as name FROM "table_with_metadata" | ||
UNION ALL | ||
SELECT NULL::string as name | ||
) group by name order by name; | ||
---- | ||
no_bar | ||
no_baz | ||
no_foo | ||
NULL | ||
|
||
query P rowsort | ||
SELECT ts | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to recommend extracting this logic into a function that is commented to help explain what it is doing -- specifically I think it is trying to get the first non-null metadata from any previous input
Reading it more closely, though, doesn't this code assume there are exactly 2 inputs to the Union? What if there are more than 2 inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that. It would be helpful to add some inline comments, or possibly extract it into another function