@@ -375,27 +375,6 @@ macro_rules! aggregate_function {
375375 } ;
376376}
377377
378- macro_rules! aggregate_function_vec_args {
379- ( $NAME: ident) => {
380- aggregate_function_vec_args!( $NAME, expr) ;
381- } ;
382- ( $NAME: ident, $( $arg: ident) * ) => {
383- #[ pyfunction]
384- #[ pyo3( signature = ( $( $arg) ,* , distinct=None , filter=None , order_by=None , null_treatment=None ) ) ]
385- fn $NAME(
386- $( $arg: PyExpr ) ,* ,
387- distinct: Option <bool >,
388- filter: Option <PyExpr >,
389- order_by: Option <Vec <PySortExpr >>,
390- null_treatment: Option <NullTreatment >
391- ) -> PyDataFusionResult <PyExpr > {
392- let agg_fn = functions_aggregate:: expr_fn:: $NAME( vec![ $( $arg. into( ) ) ,* ] ) ;
393-
394- add_builder_fns_to_aggregate( agg_fn, distinct, filter, order_by, null_treatment)
395- }
396- } ;
397- }
398-
399378/// Generates a [pyo3] wrapper for [datafusion::functions::expr_fn]
400379///
401380/// These functions have explicit named arguments.
@@ -698,8 +677,22 @@ pub fn approx_percentile_cont_with_weight(
698677 add_builder_fns_to_aggregate ( agg_fn, None , filter, None , None )
699678}
700679
701- aggregate_function_vec_args ! ( last_value) ;
680+ // We handle first_value explicitly because the signature expects an order_by
681+ // https://github.com/apache/datafusion/issues/12376
682+ #[ pyfunction]
683+ #[ pyo3( signature = ( expr, distinct=None , filter=None , order_by=None , null_treatment=None ) ) ]
684+ pub fn last_value (
685+ expr : PyExpr ,
686+ distinct : Option < bool > ,
687+ filter : Option < PyExpr > ,
688+ order_by : Option < Vec < PySortExpr > > ,
689+ null_treatment : Option < NullTreatment > ,
690+ ) -> PyDataFusionResult < PyExpr > {
691+ // If we initialize the UDAF with order_by directly, then it gets over-written by the builder
692+ let agg_fn = functions_aggregate:: expr_fn:: last_value ( expr. expr , None ) ;
702693
694+ add_builder_fns_to_aggregate ( agg_fn, distinct, filter, order_by, null_treatment)
695+ }
703696// We handle first_value explicitly because the signature expects an order_by
704697// https://github.com/apache/datafusion/issues/12376
705698#[ pyfunction]
0 commit comments