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
5 changes: 3 additions & 2 deletions vortex-array/src/aggregate_fn/accumulator_grouped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ impl<V: AggregateFnVTable> GroupedAccumulator<V> {
)?;
let mut states = builder_with_capacity(&self.partial_dtype, offsets.len());

for (offset, size) in offsets.iter().zip(sizes.iter()) {
for (i, (offset, size)) in offsets.iter().zip(sizes.iter()).enumerate() {
let offset = offset.to_usize().vortex_expect("Offset value is not usize");
let size = size.to_usize().vortex_expect("Size value is not usize");

if validity.value(offset) {
// validity is for the outer list view, so it must be indexed with `i`
if validity.value(i) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a Mask iterator is far faster than value for every function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea but I don't think we have that now. I can add one though separately

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let group = elements.slice(offset..offset + size)?;
accumulator.accumulate(&group, ctx)?;
states.append_scalar(&accumulator.flush()?)?;
Expand Down
20 changes: 20 additions & 0 deletions vortex-array/src/aggregate_fn/fns/sum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ mod tests {
use crate::arrays::ConstantArray;
use crate::arrays::DecimalArray;
use crate::arrays::FixedSizeListArray;
use crate::arrays::ListViewArray;
use crate::arrays::PrimitiveArray;
use crate::assert_arrays_eq;
use crate::dtype::DType;
Expand Down Expand Up @@ -616,6 +617,25 @@ mod tests {
Ok(())
}

#[test]
fn grouped_sum_listview_out_of_order_offsets_with_null_group() -> VortexResult<()> {
let elements =
PrimitiveArray::new(buffer![100i32, 200, 300], Validity::NonNullable).into_array();
let offsets = PrimitiveArray::new(buffer![2i32, 0, 1], Validity::NonNullable).into_array();
let sizes = PrimitiveArray::new(buffer![1i32, 1, 1], Validity::NonNullable).into_array();
let validity = Validity::from_iter([true, false, true]);
let groups = ListViewArray::try_new(elements, offsets, sizes, validity)?.into_array();

let elem_dtype = DType::Primitive(PType::I32, Nullability::NonNullable);
let result = run_grouped_sum(&groups, &elem_dtype)?;

// group 0 -> elements[2..3] = 300; group 1 -> null; group 2 -> elements[1..2] = 200.
let expected =
PrimitiveArray::from_option_iter([Some(300i64), None, Some(200i64)]).into_array();
assert_arrays_eq!(&result, &expected);
Ok(())
}

// Chunked array tests

#[test]
Expand Down
Loading