datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Reduce repetition in datafusion::functions using macros

Open alamb opened this issue 1 year ago • 1 comments

          I think it is possible to take `Vec` like what functions-array macro does
($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,
                ))
            }

Originally posted by @jayzhan211 in https://github.com/apache/datafusion/pull/10321#discussion_r1585700474

alamb avatar May 06 '24 19:05 alamb

Specifically, I think @jayzhan211 found a nice solution on the rust forums:

https://users.rust-lang.org/t/macro-repetition-with-multiple-rules/110816/2?u=jayzhan

I got a probably better solution (I had not tried it) from rust forum. To anyone that is interested in

alamb avatar May 06 '24 19:05 alamb