Skip to content

Commit 86e00b8

Browse files
committed
ifx
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent e48e277 commit 86e00b8

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

vortex-array/src/arrays/struct_/array.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::fmt::Debug;
55
use std::iter::once;
6+
use std::mem::MaybeUninit;
67
use std::sync::Arc;
78

89
use vortex_error::VortexExpect;
@@ -156,7 +157,7 @@ pub struct StructArray {
156157

157158
pub struct StructArrayParts {
158159
pub struct_fields: StructFields,
159-
pub fields: Arc<[ArrayRef]>,
160+
pub fields: Vec<ArrayRef>,
160161
pub validity: Validity,
161162
}
162163

@@ -373,6 +374,32 @@ impl StructArray {
373374
Ok(())
374375
}
375376

377+
/// Constructs a new `StructArray` from a `Vec<ArrayRef>`, avoiding an intermediate
378+
/// `Arc<[ArrayRef]>` allocation by building the slots directly from the vec.
379+
pub fn try_new_from_vec(
380+
names: FieldNames,
381+
fields: Vec<ArrayRef>,
382+
length: usize,
383+
validity: Validity,
384+
) -> VortexResult<Self> {
385+
let field_dtypes: Vec<_> = fields.iter().map(|d| d.dtype()).cloned().collect();
386+
let dtype = StructFields::new(names, field_dtypes);
387+
388+
Self::validate(&fields, &dtype, length, &validity)?;
389+
390+
let validity_slot = validity_to_child(&validity, length);
391+
let mut slots = Vec::with_capacity(1 + fields.len());
392+
slots.push(validity_slot);
393+
slots.extend(fields.into_iter().map(Some));
394+
395+
Ok(Self {
396+
len: length,
397+
dtype: DType::Struct(dtype, validity.nullability()),
398+
slots,
399+
stats_set: Default::default(),
400+
})
401+
}
402+
376403
pub fn try_new_with_dtype(
377404
fields: impl Into<Arc<[ArrayRef]>>,
378405
dtype: StructFields,
@@ -389,7 +416,7 @@ impl StructArray {
389416
pub fn into_parts(self) -> StructArrayParts {
390417
let validity = self.validity();
391418
let struct_fields = self.dtype.into_struct_fields();
392-
let fields: Arc<[ArrayRef]> = self
419+
let fields: Vec<ArrayRef> = self
393420
.slots
394421
.into_iter()
395422
.skip(FIELDS_OFFSET)

vortex-layout/src/layouts/partitioned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<P: Send + Sync + 'static> PartitionedExprEval<P> for PartitionedExpr<P> {
116116
let field_arrays = try_join_all(field_evals);
117117
let (field_arrays, mask) = try_join!(field_arrays, mask)?;
118118

119-
let root_scope = StructArray::try_new(
119+
let root_scope = StructArray::try_new_from_vec(
120120
self.partition_names.clone(),
121121
field_arrays,
122122
mask.true_count(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl LayoutReader for StructReader {
366366
.map(|a| a.clone().mask(validity.clone()))
367367
.try_collect()?;
368368

369-
Ok(StructArray::try_new(
369+
Ok(StructArray::try_new_from_vec(
370370
struct_array.names().clone(),
371371
masked_fields,
372372
struct_array.len(),

0 commit comments

Comments
 (0)