Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion vortex-array/src/aggregate_fn/fns/is_constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ impl AggregateFnVTable for IsConstant {
_args: AggregateArgs<'_, Self::Options>,
partials: ArrayRef,
) -> VortexResult<ArrayRef> {
partials.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())
// A null partial is the empty state of an empty or null group, which is not constant.
partials
.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())?
.fill_null(false)
}

fn finalize_scalar(
Expand Down Expand Up @@ -491,7 +494,9 @@ mod tests {
use crate::aggregate_fn::AggregateDTypes;
use crate::aggregate_fn::AggregateFnVTable;
use crate::aggregate_fn::DynAccumulator;
use crate::aggregate_fn::DynGroupedAccumulator;
use crate::aggregate_fn::EmptyOptions;
use crate::aggregate_fn::GroupedAccumulator;
use crate::aggregate_fn::fns::is_constant::IsConstant;
use crate::aggregate_fn::fns::is_constant::IsConstantPartial;
use crate::aggregate_fn::fns::is_constant::is_constant;
Expand All @@ -501,9 +506,11 @@ mod tests {
use crate::arrays::DecimalArray;
use crate::arrays::DictArray;
use crate::arrays::ListArray;
use crate::arrays::ListViewArray;
use crate::arrays::PrimitiveArray;
use crate::arrays::StructArray;
use crate::arrays::runend::RunEnd;
use crate::assert_arrays_eq;
use crate::builders::MapBuilder;
use crate::dtype::DType;
use crate::dtype::DecimalDType;
Expand Down Expand Up @@ -899,4 +906,32 @@ mod tests {
assert_eq!(acc.finish()?, Scalar::bool(true, Nullability::NonNullable));
Ok(())
}

#[test]
fn grouped_is_constant() -> VortexResult<()> {
let mut ctx = SESSION.create_execution_ctx();
let elements = PrimitiveArray::from_option_iter([Some(5i32), Some(5), Some(6), None, None])
.into_array();
let dtype = elements.dtype().clone();

// The groups are `[5, 5]`, `[5, 6]`, `[]`, `[null, null]`, and a null group.
let groups = ListViewArray::try_new(
elements,
buffer![0i32, 1, 0, 3, 0].into_array(),
buffer![2i32, 2, 0, 2, 0].into_array(),
Validity::from_iter([true, true, true, true, false]),
&mut ctx,
)?
.into_array();

let mut acc = GroupedAccumulator::try_new(IsConstant, EmptyOptions, dtype)?;
acc.accumulate_list(&groups, &mut ctx)?;

assert_arrays_eq!(
acc.finish()?,
BoolArray::from_iter([true, false, false, true, false]),
&mut ctx
);
Ok(())
}
}
36 changes: 35 additions & 1 deletion vortex-array/src/aggregate_fn/fns/is_sorted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ impl AggregateFnVTable for IsSorted {
_args: AggregateArgs<'_, Self::Options>,
partials: ArrayRef,
) -> VortexResult<ArrayRef> {
partials.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())
// A null partial is the empty state of an empty or null group, which is vacuously sorted.
partials
.get_item(NAMES.get(0).vortex_expect("out of bounds").clone())?
.fill_null(true)
}

fn finalize_scalar(
Expand Down Expand Up @@ -625,6 +628,8 @@ mod tests {
use crate::aggregate_fn::AggregateDTypes;
use crate::aggregate_fn::AggregateFnVTable;
use crate::aggregate_fn::DynAccumulator;
use crate::aggregate_fn::DynGroupedAccumulator;
use crate::aggregate_fn::GroupedAccumulator;
use crate::aggregate_fn::fns::is_sorted::IsSorted;
use crate::aggregate_fn::fns::is_sorted::IsSortedOptions;
use crate::aggregate_fn::fns::is_sorted::IsSortedPartial;
Expand All @@ -635,9 +640,11 @@ mod tests {
use crate::arrays::ConstantArray;
use crate::arrays::DecimalArray;
use crate::arrays::DictArray;
use crate::arrays::ListViewArray;
use crate::arrays::PrimitiveArray;
use crate::arrays::VarBinViewArray;
use crate::arrays::runend::RunEnd;
use crate::assert_arrays_eq;
use crate::dtype::DType;
use crate::dtype::DecimalDType;
use crate::dtype::Nullability;
Expand Down Expand Up @@ -943,4 +950,31 @@ mod tests {

Ok(())
}

#[rstest]
#[case::non_strict(false, [true, false, true, true, true])]
#[case::strict( true, [true, false, true, false, true])]
fn grouped_is_sorted(#[case] strict: bool, #[case] expected: [bool; 5]) -> VortexResult<()> {
let mut ctx = SESSION.create_execution_ctx();
let elements =
PrimitiveArray::from_option_iter([Some(1i32), Some(2), Some(3), Some(1), None, None])
.into_array();
let dtype = elements.dtype().clone();

// The groups are `[1, 2, 3]`, `[3, 1]`, `[]`, `[null, null]`, and a null group.
let groups = ListViewArray::try_new(
elements,
buffer![0i32, 2, 0, 4, 0].into_array(),
buffer![3i32, 2, 0, 2, 0].into_array(),
Validity::from_iter([true, true, true, true, false]),
&mut ctx,
)?
.into_array();

let mut acc = GroupedAccumulator::try_new(IsSorted, IsSortedOptions { strict }, dtype)?;
acc.accumulate_list(&groups, &mut ctx)?;

assert_arrays_eq!(acc.finish()?, BoolArray::from_iter(expected), &mut ctx);
Ok(())
}
}
Loading