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 StructArray::filter length calculation #769

Merged
merged 4 commits into from
Sep 10, 2024
Merged
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
14 changes: 6 additions & 8 deletions vortex-array/src/array/struct_/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use vortex_scalar::Scalar;
use crate::array::struct_::StructArray;
use crate::compute::unary::{scalar_at, scalar_at_unchecked, ScalarAtFn};
use crate::compute::{filter, slice, take, ArrayCompute, FilterFn, SliceFn, TakeFn};
use crate::stats::ArrayStatistics;
use crate::variants::StructArrayTrait;
use crate::{Array, ArrayDType, IntoArray};

Expand Down Expand Up @@ -79,20 +78,19 @@ impl SliceFn for StructArray {

impl FilterFn for StructArray {
fn filter(&self, predicate: &Array) -> VortexResult<Array> {
let fields = self
let fields: Vec<Array> = self
.children()
.map(|field| filter(&field, predicate))
.try_collect()?;

let predicate_true_count = predicate
.statistics()
.compute_true_count()
.ok_or_else(|| vortex_err!("Predicate should always be a boolean array"))?;
let length = fields
.first()
.map(|a| a.len())
.ok_or_else(|| vortex_err!("Struct arrays should have at least one field"))?;

Self::try_new(
self.names().clone(),
fields,
predicate_true_count,
length,
self.validity().filter(predicate)?,
)
.map(|a| a.into_array())
Expand Down
Loading