Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: support preserving reads for non-nullable group columns
  • Loading branch information
rkrishn7 committed Aug 29, 2026
commit 721c5e787d531bf5186ba22ec2dc218497839f33
32 changes: 31 additions & 1 deletion datafusion/physical-plan/src/aggregates/group_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ pub fn new_group_values(
mod tests {
use std::sync::Arc;

use arrow::array::{ArrayRef, AsArray, Int32Array, StringArray, StringViewArray};
use arrow::array::{
ArrayRef, AsArray, BooleanArray, Int32Array, StringArray, StringViewArray,
};
use arrow::datatypes::{DataType, Field, Int32Type, Schema};
use datafusion_expr::{EmitTo, GroupSelection};

Expand Down Expand Up @@ -305,6 +307,34 @@ mod tests {
assert_eq!(actual[0].as_primitive::<Int32Type>(), &expected);
}

#[test]
fn preserving_non_nullable_primitive_and_boolean_values() {
let schema = Arc::new(Schema::new(vec![
Field::new("primitive", DataType::Int32, false),
Field::new("boolean", DataType::Boolean, false),
]));
let mut group_values = new_group_values(schema, &GroupOrdering::None).unwrap();
let input = vec![
Arc::new(Int32Array::from(vec![10, 20, 10])) as ArrayRef,
Arc::new(BooleanArray::from(vec![true, false, true])) as ArrayRef,
];
let mut groups = vec![];
group_values.intern(&input, &mut groups).unwrap();
assert_eq!(groups, vec![0, 1, 0]);

let selection =
GroupSelection::try_from_indices(&[1, 0, 1], group_values.len()).unwrap();
let actual = group_values.values_preserving(selection).unwrap();
assert_eq!(
actual[0].as_primitive::<Int32Type>(),
&Int32Array::from(vec![20, 10, 20])
);
assert_eq!(
actual[1].as_boolean(),
&BooleanArray::from(vec![false, true, false])
);
}

#[test]
fn preserving_variable_width_values() {
for data_type in [DataType::Utf8, DataType::Utf8View] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ impl<const NULLABLE: bool> GroupColumn for BooleanGroupValueBuilder<NULLABLE> {
for index in selection.iter() {
values.append(self.buffer.get_bit(index));
}
let nulls = self.nulls.build_preserving(selection)?;
let nulls = if NULLABLE {
self.nulls.build_preserving(selection)?
} else {
None
};
Ok(Arc::new(BooleanArray::new(values.finish(), nulls)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ where
.iter()
.map(|index| self.group_values[index])
.collect();
let nulls = self.nulls.build_preserving(selection)?;
let nulls = if NULLABLE {
self.nulls.build_preserving(selection)?
} else {
None
};
Ok(Arc::new(
PrimitiveArray::<T>::new(ScalarBuffer::from(values), nulls)
.with_data_type(self.data_type.clone()),
Expand Down