comphead commented on code in PR #6462:
URL: https://github.com/apache/arrow-datafusion/pull/6462#discussion_r1207109304


##########
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'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 



-- 
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]

Reply via email to