Skip to content

Commit 41d2867

Browse files
jayzhan211ccciudatu
authored andcommitted
Minor: Support more args for udaf (apache#10146)
* support more args for udaf Signed-off-by: jayzhan211 <[email protected]> * fmt Signed-off-by: jayzhan211 <[email protected]> --------- Signed-off-by: jayzhan211 <[email protected]>
1 parent 41593f8 commit 41d2867

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

datafusion-cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/functions-aggregate/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ datafusion-expr = { workspace = true }
4545
datafusion-physical-expr-common = { workspace = true }
4646
log = { workspace = true }
4747
paste = "1.0.14"
48+
sqlparser = { workspace = true }

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ use datafusion_physical_expr_common::expressions;
3636
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
3737
use datafusion_physical_expr_common::sort_expr::{LexOrdering, PhysicalSortExpr};
3838
use datafusion_physical_expr_common::utils::reverse_order_bys;
39+
use sqlparser::ast::NullTreatment;
3940
use std::any::Any;
4041
use std::fmt::Debug;
4142
use std::sync::Arc;
4243

4344
make_udaf_function!(
4445
FirstValue,
4546
first_value,
46-
value,
4747
"Returns the first value in a group of values.",
4848
first_value_udaf
4949
);

datafusion/functions-aggregate/src/macros.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@
1616
// under the License.
1717

1818
macro_rules! make_udaf_function {
19-
($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
19+
($UDAF:ty, $EXPR_FN:ident, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
2020
paste::paste! {
2121
// "fluent expr_fn" style function
2222
#[doc = $DOC]
23-
pub fn $EXPR_FN($($arg: Expr),*) -> Expr {
23+
pub fn $EXPR_FN(
24+
args: Vec<Expr>,
25+
distinct: bool,
26+
filter: Option<Box<Expr>>,
27+
order_by: Option<Vec<Expr>>,
28+
null_treatment: Option<NullTreatment>
29+
) -> Expr {
2430
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
2531
$AGGREGATE_UDF_FN(),
26-
vec![$($arg),*],
27-
// TODO: Support arguments for `expr` API
28-
false,
29-
None,
30-
None,
31-
None,
32+
args,
33+
distinct,
34+
filter,
35+
order_by,
36+
null_treatment,
3237
))
3338
}
3439

datafusion/proto/tests/cases/roundtrip_logical_plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ async fn roundtrip_expr_api() -> Result<()> {
613613
lit(1),
614614
),
615615
array_replace_all(make_array(vec![lit(1), lit(2), lit(3)]), lit(2), lit(4)),
616-
first_value(lit(1)),
616+
first_value(vec![lit(1)], false, None, None, None),
617617
];
618618

619619
// ensure expressions created with the expr api can be round tripped

0 commit comments

Comments
 (0)