alamb commented on issue #9892:
URL: 
https://github.com/apache/arrow-datafusion/issues/9892#issuecomment-2040441708

   > How about we introduce `pub type ScalarFunctionImpl = Arc<dyn Fn() -> 
std::sync::Arc<datafusion_expr::ScalarUDF>>; `, so we can register the closure 
first and create the udf on demand.
   
   I was thinking maybe we can even avoid new types / macros with a function 
like this:
   
   ```rust
   fn get_udf(name: &str) -> Option<Arc<ScalarUDF>> {
     // build hash table of deferred functions that create functions on demand
     // (note this hash table would probably be built in a static OnceLock or 
something)
     let functions: HashMap<_, _> = [
       ("abs", Box::new(|| crate::math::abs()), 
       ("sin", Box::new(|| crate::math::sin()), 
       ("date_bin", Box::new(|| crate::datetime::date_bin()), 
     ...
    ].into_iter().collect();
   
     functions.get(name).map(|factory| (factor)())
   }
   ```
   
   Then we could then ensure this was in sync with a test something like
   
   ```rust
   for expected_function in datafusion_functions::all_functions() {
     assert!(get_udf(expected_function.name()).is_some())
   }
   ```


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