guojidan commented on code in PR #9343:
URL: https://github.com/apache/arrow-datafusion/pull/9343#discussion_r1505670239


##########
datafusion/functions-array/src/macros.rs:
##########
@@ -45,14 +45,14 @@
 ///
 /// [`ScalarUDFImpl`]: datafusion_expr::ScalarUDFImpl
 macro_rules! make_udf_function {
-    ($UDF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr , 
$SCALAR_UDF_FN:ident) => {
+    ($UDF:ty, $EXPR_FN:ident, $arg:ident, $DOC:expr , $SCALAR_UDF_FN:ident) => 
{

Review Comment:
   how about this, I am tested, it work well : 
   ```
   macro_rules! make_udf_function {
       ($UDF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr , 
$SCALAR_UDF_FN:ident) => {
           paste::paste! {
               // "fluent expr_fn" style function
               #[doc = $DOC]
               pub fn $EXPR_FN($($arg: Expr),*) -> Expr {
                   Expr::ScalarFunction(ScalarFunction::new_udf(
                       $SCALAR_UDF_FN(),
                       vec![$($arg),*],
                   ))
               }
   
               /// Singleton instance of [`$UDF`], ensures the UDF is only 
created once
               /// named STATIC_$(UDF). For example `STATIC_ArrayToString`
               #[allow(non_upper_case_globals)]
               static [< STATIC_ $UDF >]: 
std::sync::OnceLock<std::sync::Arc<datafusion_expr::ScalarUDF>> =
                   std::sync::OnceLock::new();
   
               /// ScalarFunction that returns a [`ScalarUDF`] for [`$UDF`]
               ///
               /// [`ScalarUDF`]: datafusion_expr::ScalarUDF
               pub fn $SCALAR_UDF_FN() -> 
std::sync::Arc<datafusion_expr::ScalarUDF> {
                   [< STATIC_ $UDF >]
                       .get_or_init(|| {
                           
std::sync::Arc::new(datafusion_expr::ScalarUDF::new_from_impl(
                               <$UDF>::new(),
                           ))
                       })
                       .clone()
               }
           }
       };
       ($UDF:ty, $EXPR_FN:ident, $DOC:expr , $SCALAR_UDF_FN:ident) => {
           paste::paste! {
               // "fluent expr_fn" style function
               #[doc = $DOC]
               pub fn $EXPR_FN(arg: Vec<Expr>) -> Expr {
                   Expr::ScalarFunction(ScalarFunction::new_udf(
                       $SCALAR_UDF_FN(),
                       arg,
                   ))
               }
   
               /// Singleton instance of [`$UDF`], ensures the UDF is only 
created once
               /// named STATIC_$(UDF). For example `STATIC_ArrayToString`
               #[allow(non_upper_case_globals)]
               static [< STATIC_ $UDF >]: 
std::sync::OnceLock<std::sync::Arc<datafusion_expr::ScalarUDF>> =
                   std::sync::OnceLock::new();
   
               /// ScalarFunction that returns a [`ScalarUDF`] for [`$UDF`]
               ///
               /// [`ScalarUDF`]: datafusion_expr::ScalarUDF
               pub fn $SCALAR_UDF_FN() -> 
std::sync::Arc<datafusion_expr::ScalarUDF> {
                   [< STATIC_ $UDF >]
                       .get_or_init(|| {
                           
std::sync::Arc::new(datafusion_expr::ScalarUDF::new_from_impl(
                               <$UDF>::new(),
                           ))
                       })
                       .clone()
               }
           }
       };
   }
   ```



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