Skip to content

Commit 47a34bd

Browse files
committed
Fix the return dtype of grouped is_constant
`GroupedAccumulator<IsConstant>::finish` failed with "Return DType mismatch". `IsConstant::finalize` read `is_constant` out of the nullable partial struct, so it returned `Bool?` instead of the non-nullable `Bool` return dtype. Empty and null groups leave a null partial, which is the empty state. Grouped `is_constant` now returns `false` for these groups, the same verdict that `finalize_scalar` gives the empty state. Signed-off-by: Connor Tsui <[email protected]>
1 parent 9dc84ce commit 47a34bd

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

  • vortex-array/src/aggregate_fn/fns/is_constant

‎vortex-array/src/aggregate_fn/fns/is_constant/mod.rs‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ impl AggregateFnVTable for IsConstant {
459459
_args: AggregateArgs<'_, Self::Options>,
460460
partials: ArrayRef,
461461
) -> VortexResult<ArrayRef> {
462-
partials.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())
462+
// A null partial is the empty state of an empty or null group, which is not constant.
463+
partials
464+
.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())?
465+
.fill_null(false)
463466
}
464467

465468
fn finalize_scalar(
@@ -491,7 +494,9 @@ mod tests {
491494
use crate::aggregate_fn::AggregateDTypes;
492495
use crate::aggregate_fn::AggregateFnVTable;
493496
use crate::aggregate_fn::DynAccumulator;
497+
use crate::aggregate_fn::DynGroupedAccumulator;
494498
use crate::aggregate_fn::EmptyOptions;
499+
use crate::aggregate_fn::GroupedAccumulator;
495500
use crate::aggregate_fn::fns::is_constant::IsConstant;
496501
use crate::aggregate_fn::fns::is_constant::IsConstantPartial;
497502
use crate::aggregate_fn::fns::is_constant::is_constant;
@@ -501,9 +506,11 @@ mod tests {
501506
use crate::arrays::DecimalArray;
502507
use crate::arrays::DictArray;
503508
use crate::arrays::ListArray;
509+
use crate::arrays::ListViewArray;
504510
use crate::arrays::PrimitiveArray;
505511
use crate::arrays::StructArray;
506512
use crate::arrays::runend::RunEnd;
513+
use crate::assert_arrays_eq;
507514
use crate::builders::MapBuilder;
508515
use crate::dtype::DType;
509516
use crate::dtype::DecimalDType;
@@ -899,4 +906,32 @@ mod tests {
899906
assert_eq!(acc.finish()?, Scalar::bool(true, Nullability::NonNullable));
900907
Ok(())
901908
}
909+
910+
#[test]
911+
fn grouped_is_constant() -> VortexResult<()> {
912+
let mut ctx = SESSION.create_execution_ctx();
913+
let elements = PrimitiveArray::from_option_iter([Some(5i32), Some(5), Some(6), None, None])
914+
.into_array();
915+
let dtype = elements.dtype().clone();
916+
917+
// The groups are `[5, 5]`, `[5, 6]`, `[]`, `[null, null]`, and a null group.
918+
let groups = ListViewArray::try_new(
919+
elements,
920+
buffer![0i32, 1, 0, 3, 0].into_array(),
921+
buffer![2i32, 2, 0, 2, 0].into_array(),
922+
Validity::from_iter([true, true, true, true, false]),
923+
&mut ctx,
924+
)?
925+
.into_array();
926+
927+
let mut acc = GroupedAccumulator::try_new(IsConstant, EmptyOptions, dtype)?;
928+
acc.accumulate_list(&groups, &mut ctx)?;
929+
930+
assert_arrays_eq!(
931+
acc.finish()?,
932+
BoolArray::from_iter([true, false, false, true, false]),
933+
&mut ctx
934+
);
935+
Ok(())
936+
}
902937
}

0 commit comments

Comments
 (0)