-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix duplicate field name error in Join::try_new_with_project_input during physical planning #16454
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
Draft
LiaCastaneda
wants to merge
1
commit into
apache:main
Choose a base branch
from
LiaCastaneda:lia/fix-duplicate-unqualified-from-physcial-planning-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1667,6 +1667,34 @@ pub fn build_join_schema( | |
dfschema.with_functional_dependencies(func_dependencies) | ||
} | ||
|
||
/// (Re)qualify the sides of a join if needed, i.e. if the columns from one side would otherwise | ||
/// conflict with the columns from the other. | ||
/// This is especially useful for queries that come as Substrait, since Substrait doesn't currently allow specifying | ||
/// aliases, neither for columns nor for tables. DataFusion requires columns to be uniquely identifiable, in some | ||
/// places (see e.g. DFSchema::check_names). | ||
pub fn requalify_sides_if_needed( | ||
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 moved this helper function to the logical plan |
||
left: LogicalPlanBuilder, | ||
right: LogicalPlanBuilder, | ||
) -> Result<(LogicalPlanBuilder, LogicalPlanBuilder, bool)> { | ||
let left_cols = left.schema().columns(); | ||
let right_cols = right.schema().columns(); | ||
if left_cols.iter().any(|l| { | ||
right_cols.iter().any(|r| { | ||
l == r || (l.name == r.name && (l.relation.is_none() || r.relation.is_none())) | ||
}) | ||
}) { | ||
// These names have no connection to the original plan, but they'll make the columns | ||
// (mostly) unique. | ||
Ok(( | ||
left.alias(TableReference::bare("left"))?, | ||
right.alias(TableReference::bare("right"))?, | ||
true, | ||
)) | ||
} else { | ||
Ok((left, right, false)) | ||
} | ||
} | ||
|
||
/// Add additional "synthetic" group by expressions based on functional | ||
/// dependencies. | ||
/// | ||
|
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The rationale for qualifying the schema is that when building the logical
Projection
after, it will build the fields out of the expression names in exprlist_to_fields so it will look innew_join.schema()
and try to match each expr to a field in the schema, if the expr::Column does not have a qualifier and there are multiple candidatesFields
that could correspond to this expr::Column , we will get an ambiguity error, qualifying the schema allows us to prevent this.