You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/05/26 16:41:18 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6462: Improve `BuiltInFunction` Name Lookup

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


##########
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:
   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 🤔 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org