File tree Expand file tree Collapse file tree
datafusion/functions-aggregate/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3383,4 +3383,38 @@ mod tests {
33833383
33843384 Ok ( ( ) )
33853385 }
3386+
3387+ #[ test]
3388+ fn test_first_value_unordered_groups_accumulator ( ) -> Result < ( ) > {
3389+ let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int64 , true ) ] ) ;
3390+ let exprs = [ col ( "a" , & schema) ?] ;
3391+ let expr_fields = [ Arc :: new ( Field :: new ( "a" , DataType :: Int64 , true ) ) ] ;
3392+ let args = || AccumulatorArgs {
3393+ return_field : Arc :: new ( Field :: new ( "f" , DataType :: Int64 , true ) ) ,
3394+ schema : & schema,
3395+ expr_fields : & expr_fields,
3396+ ignore_nulls : false ,
3397+ order_bys : & [ ] ,
3398+ is_reversed : false ,
3399+ name : "first_value(a)" ,
3400+ is_distinct : false ,
3401+ exprs : & exprs,
3402+ } ;
3403+
3404+ // Without ORDER BY, FIRST_VALUE uses its own grouped accumulator
3405+ // rather than falling back to `GroupsAccumulatorAdapter`.
3406+ let first_value = FirstValue :: new ( ) ;
3407+ assert ! ( first_value. groups_accumulator_supported( args( ) ) ) ;
3408+ let group_acc = first_value. create_groups_accumulator ( args ( ) ) ?;
3409+ let group_acc: & dyn std:: any:: Any = group_acc. as_ref ( ) ;
3410+ assert ! (
3411+ group_acc
3412+ . is:: <UnorderedFirstValueGroupsAccumulator <PrimitiveValueState <Int64Type >>>( )
3413+ ) ;
3414+
3415+ // LAST_VALUE still requires an ordering.
3416+ assert ! ( !LastValue :: new( ) . groups_accumulator_supported( args( ) ) ) ;
3417+
3418+ Ok ( ( ) )
3419+ }
33863420}
You can’t perform that action at this time.
0 commit comments