-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve BuiltInFunction Name Lookup
#6462
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
BuiltInFunction Name Lookup
| write!(f, "{}", func_name) | ||
| } else { | ||
| // Should not be reached | ||
| panic!("Internal error: {self:?} not in ALL_FUNCTIONS list"); |
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.
Everything is great and needed, one nit, do we need to panic?
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 panic will occur if someone adds a new BuiltInFunction and doesn't add it to the built in list.
I can remove the panic but then if someone doesn't add the function to the new LIST I was worried the error would be masked (the wrong function name would be used or the lookup might fail). But maybe that is preferable 🤔
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'm thinking wouldn't be that better to implement a function name
fn name(func: BuiltinScalarFunction) -> Result<String> {
match func {
BuiltinScalarFunction::Abs => "abs"
....
}
}
This will ensure on compile time the newly added function gets its string alias
Then we can build the hashmaps the same way over iterating BuiltinScalarFunction enum
for func in BuiltinScalarFunction::iter() {
let name = name(func);
hashmapLookup.insert(name, func);
hashmapRevLookup.insert(func, name);
}
I can play with this and create another PR
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 can play with this and create another PR
Thank you 🙏
Note one gotcha you might hit is that the mapping is one-> many
So you might need something like
/// returns all the names that can be used for this function
fn names(func: BuiltinScalarFunction) -> &[&'str]] {
match func {
BuiltinScalarFunction::Abs => "abs"
....
}
}|
I forget to mention in the original PR #6448 : the rationale behind storing the mapping ( Also I thought iterating through a small vector several times is not likely to be the performance issue for an analytical system, so the original implementation is trying to make the code more maintainable and avoid over-engineering. |
Which issue does this PR close?
related to #6448
Rationale for this change
While reviewing #6448 from @2010YOUY01 I was somewhat worried about the performance impact of doing linear searches for function names.
What changes are included in this PR?
HashMaps from function name table and use them in lookupspanicif there is no corresponding entry for displaying a BuiltInFunctionAre these changes tested?
Are there any user-facing changes?