Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly handle take on dense union of a single selected type #6209

Merged
merged 4 commits into from
Aug 8, 2024
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: 1 addition & 4 deletions arrow-select/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,7 @@ fn filter_native<T: ArrowNativeType>(values: &[T], predicate: &FilterPredicate)
}

/// `filter` implementation for primitive arrays
pub(crate) fn filter_primitive<T>(
array: &PrimitiveArray<T>,
predicate: &FilterPredicate,
) -> PrimitiveArray<T>
fn filter_primitive<T>(array: &PrimitiveArray<T>, predicate: &FilterPredicate) -> PrimitiveArray<T>
where
T: ArrowPrimitiveType,
{
Expand Down
27 changes: 21 additions & 6 deletions arrow-select/src/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use arrow_schema::{ArrowError, DataType, FieldRef, UnionMode};

use num::{One, Zero};

use crate::filter::{filter_primitive, FilterBuilder};

/// Take elements by index from [Array], creating a new [Array] from those indexes.
///
/// ```text
Expand Down Expand Up @@ -251,13 +249,12 @@ fn take_impl<IndexType: ArrowPrimitiveType>(
let children = fields.iter()
.map(|(field_type_id, _)| {
let mask = BooleanArray::from_unary(&type_ids, |value_type_id| value_type_id == field_type_id);
let predicate = FilterBuilder::new(&mask).build();

let indices = filter_primitive(&offsets, &predicate);
let indices = crate::filter::filter(&offsets, &mask)?;

let values = values.child(field_type_id);

take_impl(values, &indices)
take_impl(values, indices.as_primitive::<Int32Type>())
})
.collect::<Result<_, _>>()?;

Expand Down Expand Up @@ -885,7 +882,7 @@ mod tests {
use super::*;
use arrow_array::builder::*;
use arrow_buffer::{IntervalDayTime, IntervalMonthDayNano};
use arrow_schema::{Field, Fields, TimeUnit};
use arrow_schema::{Field, Fields, TimeUnit, UnionFields};

fn test_take_decimal_arrays(
data: Vec<Option<i128>>,
Expand Down Expand Up @@ -2308,4 +2305,22 @@ mod tests {
take(&union, &indices, None).unwrap().to_data()
);
}

#[test]
fn test_take_union_dense_all_match_issue_6206() {
let fields = UnionFields::new(vec![0], vec![Field::new("a", DataType::Int64, false)]);
let ints = Arc::new(Int64Array::from(vec![1, 2, 3, 4, 5]));

let array = UnionArray::try_new(
fields,
ScalarBuffer::from(vec![0_i8, 0, 0, 0, 0]),
Some(ScalarBuffer::from_iter(0_i32..5)),
vec![ints],
)
.unwrap();

let indicies = Int64Array::from(vec![0, 2, 4]);
let array = take(&array, &indicies, None).unwrap();
assert_eq!(array.len(), 3);
}
}
Loading