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

Remove redundant upper case aliases for median, first_value and last_value #10696

Merged
merged 5 commits into from
May 29, 2024

Conversation

goldmedal
Copy link
Contributor

Which issue does this PR close?

Closes #10695 .

Rationale for this change

What changes are included in this PR?

Fix median, first_value and last_value

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label May 28, 2024
@github-actions github-actions bot added the optimizer Optimizer rules label May 28, 2024
@@ -72,7 +72,7 @@ impl Default for FirstValue {
impl FirstValue {
pub fn new() -> Self {
Self {
aliases: vec![String::from("first_value")],
aliases: vec![],
Copy link
Contributor

Choose a reason for hiding this comment

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

A minor comment is we can probably remove the aliases field entirely and just return an empty slice

    fn aliases(&self) -> &[String] {
        &[]
    }

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 @goldmedal -- this looks great.

cc @jayzhan211

@@ -109,13 +109,13 @@ mod tests {
let mut names = HashSet::new();
for func in all_default_aggregate_functions() {
assert!(
names.insert(func.name().to_string()),
names.insert(func.name().to_string().to_lowercase()),
Copy link
Contributor

@jayzhan211 jayzhan211 May 29, 2024

Choose a reason for hiding this comment

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

Can we not convert to lowercase here? If someone changes the name to uppercase again, the function in the function map (lowercase) is not the same as the function name (uppercase), and it is easy to introduce a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jayzhan211
I think to_lowercase is used to ensure that the function name and its alias won't be duplicates when case-insensitive (e.g., unquoted identifier). If someone changes the function name to uppercase, the test will pass. However, they may find that they can't query this function in lowercase. They might try to add a lowercase alias or change the function name back to lowercase. I think this is the purpose of this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it is the test, then it is fine

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@jayzhan211 jayzhan211 merged commit 08e19f4 into apache:main May 29, 2024
23 checks passed
@goldmedal goldmedal deleted the enhacement/udaf-name-upper branch May 29, 2024 06:53
@goldmedal
Copy link
Contributor Author

Thanks again @alamb @jayzhan211

findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
…last_value` (apache#10696)

* change udaf name to lowercase

* enhance test for duplicate function name

* fix test

* fix tests

* remove redundant alias field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use lowercase name for aggregate function
3 participants