Skip to content

Commit bc10975

Browse files
committed
fix validity masking
Signed-off-by: Andrew Duffy <[email protected]>
1 parent 5d204a4 commit bc10975

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

vortex-layout/src/layouts/struct_/reader.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use std::sync::Arc;
77

88
use futures::try_join;
99
use itertools::Itertools;
10+
use vortex_array::arrays::{StructArray, StructVTable};
1011
use vortex_array::stats::Precision;
11-
use vortex_array::{MaskFuture, ToCanonical};
12-
use vortex_dtype::{DType, FieldMask, FieldName, Nullability, StructFields};
12+
use vortex_array::validity::Validity;
13+
use vortex_array::{ArrayRef, IntoArray, MaskFuture, ToCanonical};
14+
use vortex_dtype::{DType, FieldDType, FieldMask, FieldName, Nullability, StructFields};
1315
use vortex_error::{VortexExpect, VortexResult, vortex_err};
1416
use vortex_expr::transform::immediate_access::annotate_scope_access;
1517
use vortex_expr::transform::{
@@ -293,10 +295,33 @@ impl LayoutReader for StructReader {
293295
// can return a result of different length (e.g. `UNNEST`) then this becomes
294296
// more complicated.
295297
let (validity, projection) = try_join!(validity_fut, projection_fut)?;
296-
vortex_array::compute::mask(
297-
projection.as_ref(),
298-
&Mask::from_buffer(!validity.to_bool().boolean_buffer()),
299-
)
298+
299+
// The expression partitioner takes care of re-packing the projection results into
300+
// a new struct array.
301+
// Since the pack is always present, we apply the validity back onto the children
302+
// directly.
303+
304+
let projection_struct = projection.as_::<StructVTable>().clone();
305+
let field_names = projection_struct.struct_fields().names().clone();
306+
307+
let fields: Vec<ArrayRef> = projection_struct
308+
.fields()
309+
.iter()
310+
.map(|field| {
311+
vortex_array::compute::mask(
312+
field.as_ref(),
313+
&Mask::from_buffer(!validity.to_bool().boolean_buffer()),
314+
)
315+
})
316+
.try_collect()?;
317+
318+
Ok(StructArray::try_new(
319+
field_names,
320+
fields,
321+
projection_struct.len(),
322+
Validity::NonNullable,
323+
)?
324+
.into_array())
300325
} else {
301326
projection_fut.await
302327
}

0 commit comments

Comments
 (0)