Skip to content
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

Use qualified aliases to simplify searching DFSchema #12546

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

jonahgao
Copy link
Member

Which issue does this PR close?

N/A.

Rationale for this change

The following logic was introduced for single_distinct_to_groupby in #4050.
The reason was the lack of alias-with-qualifier, which caused the qualifier to be lost after alias. See comment
When searching for a qualified name in DFSchema, we must also check unqualified fields because they may have been aliased and previously had a qualifier. We can now use qualified aliases to avoid this.

(Some(qq), None) => {
// the original field may now be aliased with a name that matches the
// original qualified name
let column = Column::from_qualified_name(f.name());
match column {
Column {
relation: Some(r),
name: column_name,
} => &r == qq && column_name == name,
_ => false,
}
}

What changes are included in this PR?

Are these changes tested?

By existing tests.

Are there any user-facing changes?

No

@github-actions github-actions bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Sep 20, 2024

# Can't reference an unqualified column by a qualified name
query error DataFusion error: Schema error: No field named t1\.v1\. Valid fields are "t1\.v1"\.
SELECT t1.v1 FROM (SELECT 1 AS "t1.v1");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query will not produce an error on main branch, which is incorrect.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jonahgao -- this makes sense to me. Given all the tests are passing I think it is good to go 🚀

@jonahgao jonahgao merged commit d73c9d8 into apache:main Sep 23, 2024
24 checks passed
@jonahgao
Copy link
Member Author

Thanks @alamb for the review

@jonahgao jonahgao deleted the alias_qualified branch September 23, 2024 02:16
bgjackma pushed a commit to bgjackma/datafusion that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants