datafusion_functions_aggregate/
macros.rs1macro_rules! make_udaf_expr {
19 ($EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
20 #[doc = $DOC]
22 pub fn $EXPR_FN(
23 $($arg: datafusion_expr::Expr,)*
24 ) -> datafusion_expr::Expr {
25 datafusion_expr::Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
26 $AGGREGATE_UDF_FN(),
27 vec![$($arg),*],
28 false,
29 None,
30 None,
31 None,
32 ))
33 }
34 };
35}
36
37macro_rules! make_udaf_expr_and_func {
38 ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
39 make_udaf_expr!($EXPR_FN, $($arg)*, $DOC, $AGGREGATE_UDF_FN);
40 create_func!($UDAF, $AGGREGATE_UDF_FN);
41 };
42 ($UDAF:ty, $EXPR_FN:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
43 #[doc = $DOC]
45 pub fn $EXPR_FN(
46 args: Vec<datafusion_expr::Expr>,
47 ) -> datafusion_expr::Expr {
48 datafusion_expr::Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
49 $AGGREGATE_UDF_FN(),
50 args,
51 false,
52 None,
53 None,
54 None,
55 ))
56 }
57
58 create_func!($UDAF, $AGGREGATE_UDF_FN);
59 };
60}
61
62macro_rules! create_func {
63 ($UDAF:ty, $AGGREGATE_UDF_FN:ident) => {
64 create_func!($UDAF, $AGGREGATE_UDF_FN, <$UDAF>::default());
65 };
66 ($UDAF:ty, $AGGREGATE_UDF_FN:ident, $CREATE:expr) => {
67 paste::paste! {
68 #[doc = concat!("AggregateFunction that returns a [`AggregateUDF`](datafusion_expr::AggregateUDF) for [`", stringify!($UDAF), "`]")]
69 pub fn $AGGREGATE_UDF_FN() -> std::sync::Arc<datafusion_expr::AggregateUDF> {
70 static INSTANCE: std::sync::LazyLock<std::sync::Arc<datafusion_expr::AggregateUDF>> =
72 std::sync::LazyLock::new(|| {
73 std::sync::Arc::new(datafusion_expr::AggregateUDF::from($CREATE))
74 });
75 std::sync::Arc::clone(&INSTANCE)
76 }
77 }
78 }
79}