Skip to content

Commit

Permalink
Fix StructArray::filter length calculation (#769)
Browse files Browse the repository at this point in the history
there's no need to calculate states here, we can just use the length of
a filtered array
  • Loading branch information
AdamGS authored Sep 10, 2024
1 parent edb014b commit bcae104
Showing 1 changed file with 6 additions and 8 deletions.
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

0 comments on commit bcae104

Please sign in to comment.