Skip to content

Commit c36da6e

Browse files
committed
test: check FirstValue creates the unordered groups accumulator
1 parent 35b4063 commit c36da6e

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎datafusion/functions-aggregate/src/first_last.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)