-
Notifications
You must be signed in to change notification settings - Fork 1.9k
reduce search complexity for BuiltinScalarFunction #6479
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
Conversation
2010YOUY01
left a comment
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.
This implementation makes it very clear what code to change when adding new functions. Suggested some minor changes, but overall looks good to me, thank you!
| static ref FUNCTION_TO_NAME: HashMap<BuiltinScalarFunction, &'static str> = { | ||
| let mut map: HashMap<BuiltinScalarFunction, &'static str> = HashMap::new(); | ||
| BuiltinScalarFunction::iter().for_each(|func| { | ||
| map.insert(func, aliases(&func).iter().next().unwrap_or(&"NO_ALIAS")); |
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.
.iter().next() == .first()
| } | ||
| } | ||
| } | ||
|
|
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.
/// First alias in the array is used to display function names
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.
what is that?
| if func == self { | ||
| return write!(f, "{}", func_name); | ||
| } | ||
| fn aliases(func: &BuiltinScalarFunction) -> &'static [&'static str] { |
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.
Sorry I commented on the wrong line previously @comphead , should be here.
Adding a comment for aliases():
/// First alias in the array is used to display function names
alamb
left a comment
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.
Thanks @comphead and @2010YOUY01
| BuiltinScalarFunction::CurrentDate => &["current_date"], | ||
| BuiltinScalarFunction::CurrentTime => &["current_time"], | ||
| BuiltinScalarFunction::DateBin => &["date_bin"], | ||
| BuiltinScalarFunction::DateTrunc => &["date_trunc", "datetrunc"], |
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 like how this formulation makes it easier to understand what functions have aliases and which do not 👍
|
I think this PR looks good to go and all outstanding comments have been addressed, so merging it in 🚀 |
Which issue does this PR close?
Related #6448.
Closes #6462
Rationale for this change
Reduce search complexity when mapping BuiltinScalarFunction and its alias. Currently it is linear search and the place becoming a hotspot. The change is to make the search O(1) using static maps
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
No