apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.21k stars 957 forks source link

Reduce repetition in datafusion::functions using macros #10397

Open alamb opened 1 week ago

alamb commented 1 week ago
          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 commented 1 week ago

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