Skip to content

Commit e5061a4

Browse files
committed
Ignore empty Constant batches in aggregates
Signed-off-by: Connor Tsui <[email protected]>
1 parent c07196e commit e5061a4

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ impl AggregateFnVTable for IsConstant {
379379

380380
match batch {
381381
Columnar::Constant(c) => {
382+
if c.is_empty() {
383+
return Ok(());
384+
}
385+
382386
partial.check_value(c.scalar().clone().into_nullable());
383387
Ok(())
384388
}
@@ -480,6 +484,7 @@ mod tests {
480484
use crate::array_session;
481485
use crate::arrays::BoolArray;
482486
use crate::arrays::ChunkedArray;
487+
use crate::arrays::ConstantArray;
483488
use crate::arrays::DecimalArray;
484489
use crate::arrays::ListArray;
485490
use crate::arrays::PrimitiveArray;
@@ -782,6 +787,18 @@ mod tests {
782787
Ok(())
783788
}
784789

790+
#[test]
791+
fn empty_constant_leaves_partial_empty() -> VortexResult<()> {
792+
let mut ctx = array_session().create_execution_ctx();
793+
let array = ConstantArray::new(Scalar::from(99i32), 0).into_array();
794+
let mut acc = Accumulator::try_new(IsConstant, EmptyOptions, array.dtype().clone())?;
795+
796+
acc.accumulate(&array, &mut ctx)?;
797+
798+
assert!(acc.partial_scalar()?.is_null());
799+
Ok(())
800+
}
801+
785802
/// Merging a non-constant partial into a materialized empty one must keep the false verdict
786803
/// in the partial scalar rather than collapsing it to the empty state.
787804
#[test]

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ impl AggregateFnVTable for IsSorted {
428428

429429
match batch {
430430
Columnar::Constant(c) => {
431+
if c.is_empty() {
432+
return Ok(());
433+
}
434+
431435
// Constant arrays are sorted but not strict sorted (if len > 1).
432436
let value = c.scalar().clone().into_nullable();
433437
if args.options.strict && c.len() > 1 {
@@ -597,6 +601,7 @@ mod tests {
597601
use crate::aggregate_fn::fns::is_sorted::is_strict_sorted;
598602
use crate::array_session;
599603
use crate::arrays::BoolArray;
604+
use crate::arrays::ConstantArray;
600605
use crate::arrays::PrimitiveArray;
601606
use crate::dtype::DType;
602607
use crate::dtype::Nullability;
@@ -753,6 +758,19 @@ mod tests {
753758
Ok(())
754759
}
755760

761+
#[test]
762+
fn empty_constant_leaves_partial_empty() -> VortexResult<()> {
763+
let mut ctx = array_session().create_execution_ctx();
764+
let array = ConstantArray::new(Scalar::from(99i32), 0).into_array();
765+
let options = IsSortedOptions { strict: false };
766+
let mut acc = Accumulator::try_new(IsSorted, options, array.dtype().clone())?;
767+
768+
acc.accumulate(&array, &mut ctx)?;
769+
770+
assert!(acc.partial_scalar()?.is_null());
771+
Ok(())
772+
}
773+
756774
/// Merging an unsorted partial into a materialized empty one must keep the false verdict in
757775
/// both the finalized result and the partial scalar.
758776
#[test]

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ impl AggregateFnVTable for MinMax {
419419
) -> VortexResult<()> {
420420
match batch {
421421
Columnar::Constant(c) => {
422+
if c.is_empty() {
423+
return Ok(());
424+
}
425+
422426
let scalar = c.scalar();
423427
if scalar.is_null() {
424428
return Ok(());
@@ -1081,6 +1085,19 @@ mod tests {
10811085
Ok(())
10821086
}
10831087

1088+
#[test]
1089+
fn empty_constant_leaves_partial_empty() -> VortexResult<()> {
1090+
let mut ctx = SESSION.create_execution_ctx();
1091+
let array = ConstantArray::new(Scalar::from(99i32), 0).into_array();
1092+
let options = NumericalAggregateOpts::default();
1093+
let mut acc = Accumulator::try_new(MinMax, options, array.dtype().clone())?;
1094+
1095+
acc.accumulate(&array, &mut ctx)?;
1096+
1097+
assert!(acc.partial_scalar()?.is_null());
1098+
Ok(())
1099+
}
1100+
10841101
/// Regression test for <https://github.com/vortex-data/vortex/issues/8145>.
10851102
///
10861103
/// A chunked array whose first chunk is an *empty* constant array — as produced by

0 commit comments

Comments
 (0)