alamb commented on code in PR #6462:
URL: https://github.com/apache/arrow-datafusion/pull/6462#discussion_r1207115134
##########
datafusion/expr/src/built_in_function.rs:
##########
@@ -431,29 +452,21 @@ impl BuiltinScalarFunction {
impl fmt::Display for BuiltinScalarFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- for (func_name, func) in NAME_TO_FUNCTION.iter() {
- if func == self {
- return write!(f, "{}", func_name);
- }
+ if let Some(func_name) = FUNCTION_TO_NAME.get(self) {
+ write!(f, "{}", func_name)
+ } else {
+ // Should not be reached
+ panic!("Internal error: {self:?} not in ALL_FUNCTIONS list");
Review Comment:
> 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
```sql
/// returns all the names that can be used for this function
fn names(func: BuiltinScalarFunction) -> &[&'str]] {
match func {
BuiltinScalarFunction::Abs => "abs"
....
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]