From 50d328f8a15489959b949c912aebbfe325358805 Mon Sep 17 00:00:00 2001 From: jayzhan211 Date: Tue, 14 May 2024 09:04:47 +0800 Subject: [PATCH 1/2] adjust macro args Signed-off-by: jayzhan211 --- datafusion/functions-aggregate/src/macros.rs | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/datafusion/functions-aggregate/src/macros.rs b/datafusion/functions-aggregate/src/macros.rs index 27fc623a182b..f65ea541d46c 100644 --- a/datafusion/functions-aggregate/src/macros.rs +++ b/datafusion/functions-aggregate/src/macros.rs @@ -15,8 +15,63 @@ // specific language governing permissions and limitations // under the License. +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + macro_rules! make_udaf_expr_and_func { + // e.g. fun(arg) ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { + // "fluent expr_fn" style function + #[doc = $DOC] + pub fn $EXPR_FN( + $($arg: datafusion_expr::Expr,)* + ) -> datafusion_expr::Expr { + datafusion_expr::Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf( + $AGGREGATE_UDF_FN(), + vec![$($arg),*], + false, + None, + None, + None, + )) + } + create_func!($UDAF, $AGGREGATE_UDF_FN); + }; + // e.g. fun(arg, distinct) + ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $distinct:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { + // "fluent expr_fn" style function + #[doc = $DOC] + pub fn $EXPR_FN( + $($arg: datafusion_expr::Expr,)* + distinct: bool, + ) -> datafusion_expr::Expr { + datafusion_expr::Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf( + $AGGREGATE_UDF_FN(), + vec![$($arg),*], + distinct, + None, + None, + None + )) + } + create_func!($UDAF, $AGGREGATE_UDF_FN); + }; + // e.g. fun(arg, distinct, filter, order_by, null_treatment) + ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $distinct:ident, $filter:ident, $order_by:ident, $null_treatment:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { // "fluent expr_fn" style function #[doc = $DOC] pub fn $EXPR_FN( @@ -37,6 +92,7 @@ macro_rules! make_udaf_expr_and_func { } create_func!($UDAF, $AGGREGATE_UDF_FN); }; + // e.g. func(vec![arg], distinct, filter, order_by, null_treatment) ($UDAF:ty, $EXPR_FN:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { // "fluent expr_fn" style function #[doc = $DOC] From 1d15d0efa902a69283b2d930e33ee31723cb416f Mon Sep 17 00:00:00 2001 From: jayzhan211 Date: Tue, 14 May 2024 09:05:23 +0800 Subject: [PATCH 2/2] adjust macro rule Signed-off-by: jayzhan211 --- datafusion/functions-aggregate/src/macros.rs | 25 ------------------- .../tests/cases/roundtrip_logical_plan.rs | 4 +-- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/datafusion/functions-aggregate/src/macros.rs b/datafusion/functions-aggregate/src/macros.rs index f65ea541d46c..6c3348d6c1d6 100644 --- a/datafusion/functions-aggregate/src/macros.rs +++ b/datafusion/functions-aggregate/src/macros.rs @@ -33,7 +33,6 @@ // under the License. macro_rules! make_udaf_expr_and_func { - // e.g. fun(arg) ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { // "fluent expr_fn" style function #[doc = $DOC] @@ -51,7 +50,6 @@ macro_rules! make_udaf_expr_and_func { } create_func!($UDAF, $AGGREGATE_UDF_FN); }; - // e.g. fun(arg, distinct) ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $distinct:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { // "fluent expr_fn" style function #[doc = $DOC] @@ -70,29 +68,6 @@ macro_rules! make_udaf_expr_and_func { } create_func!($UDAF, $AGGREGATE_UDF_FN); }; - // e.g. fun(arg, distinct, filter, order_by, null_treatment) - ($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $distinct:ident, $filter:ident, $order_by:ident, $null_treatment:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { - // "fluent expr_fn" style function - #[doc = $DOC] - pub fn $EXPR_FN( - $($arg: datafusion_expr::Expr,)* - distinct: bool, - filter: Option>, - order_by: Option>, - null_treatment: Option - ) -> datafusion_expr::Expr { - datafusion_expr::Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf( - $AGGREGATE_UDF_FN(), - vec![$($arg),*], - distinct, - filter, - order_by, - null_treatment, - )) - } - create_func!($UDAF, $AGGREGATE_UDF_FN); - }; - // e.g. func(vec![arg], distinct, filter, order_by, null_treatment) ($UDAF:ty, $EXPR_FN:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => { // "fluent expr_fn" style function #[doc = $DOC] diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs index ec215937dca8..b5b0b4c2247a 100644 --- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs @@ -622,8 +622,8 @@ async fn roundtrip_expr_api() -> Result<()> { ), array_replace_all(make_array(vec![lit(1), lit(2), lit(3)]), lit(2), lit(4)), first_value(vec![lit(1)], false, None, None, None), - covar_samp(lit(1.5), lit(2.2), false, None, None, None), - covar_pop(lit(1.5), lit(2.2), true, None, None, None), + covar_samp(lit(1.5), lit(2.2)), + covar_pop(lit(1.5), lit(2.2)), ]; // ensure expressions created with the expr api can be round tripped