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

fix: ignore case when matching function name #16912

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

notauserx
Copy link

@notauserx notauserx commented Nov 22, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Update logic to search by the lowercase of func_name. Uses unicode crate to facilitate searching function name ignoring case

fixes: #16737

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@notauserx notauserx changed the title add method to check sugar function fix: ignore case when matching function name Nov 22, 2024
@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Nov 22, 2024
@TCeason TCeason requested a review from andylokandy November 25, 2024 02:23
Copy link
Collaborator

@TCeason TCeason left a comment

Choose a reason for hiding this comment

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

LGTM

@notauserx
Copy link
Author

Does it make sense to add ignore case search in is_builtin_function(func_name) as well?

@@ -721,9 +721,7 @@ impl<'a> TypeChecker<'a> {
} => {
let func_name = normalize_identifier(name, self.name_resolution_ctx).to_string();
let func_name = func_name.as_str();
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about handling case here?

Suggested change
let func_name = func_name.as_str();
let func_name = func_name.to_lowercase();

Copy link
Author

@notauserx notauserx Nov 25, 2024

Choose a reason for hiding this comment

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

Good suggestion.

Since sugar and built-in functions are matched ignoring case, that's why I created a sep function and moved the logic inside there, and we could do the same in is_builtin_function, otherwise each caller has to convert to lower case before calling the functions

Copy link
Collaborator

@andylokandy andylokandy Nov 25, 2024

Choose a reason for hiding this comment

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

Ok. I see. Then I'll suggest replacing &str in all_sugar_functions and builtin_functions to https://crates.io/crates/unicase

Copy link
Author

Choose a reason for hiding this comment

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

I've used the Ascii type from the unicase crate, a case-insensitive wrapper for ASCII strings. Is this assumption correct? If not, I can switch to the UniCase type, which provides a case-insensitive wrapper for general strings.

@sundy-li
Copy link
Member

Let's add a test in name_hit.test to cover the issue.

@notauserx notauserx force-pushed the fix-search-by-lowercase-func-name branch 2 times, most recently from f64459f to 5ad40f7 Compare November 27, 2024 15:58
@notauserx notauserx force-pushed the fix-search-by-lowercase-func-name branch from c08754d to d4bd725 Compare November 27, 2024 18:50
@notauserx
Copy link
Author

Let's add a test in name_hit.test to cover the issue.

Added a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants