Skip to content

Commit 1bfa40e

Browse files
authored
perf: use individual field access for maybe_null_field_by_idx (#1881)
Part of #1749 This notably improves compression speed for tables with wide schemas.
1 parent 93f8cb5 commit 1bfa40e

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,24 @@ impl VariantsVTable<StructArray> for StructEncoding {
150150

151151
impl StructArrayTrait for StructArray {
152152
fn maybe_null_field_by_idx(&self, idx: usize) -> Option<ArrayData> {
153-
self.dtypes().get(idx).map(|dtype| {
154-
self.as_ref()
155-
.child(idx, dtype, self.len())
156-
.unwrap_or_else(|e| vortex_panic!(e, "StructArray: field {} not found", idx))
157-
})
153+
Some(
154+
self.field_info(&Field::Index(idx))
155+
.map(|field_info| {
156+
self.as_ref()
157+
.child(
158+
idx,
159+
&field_info
160+
.dtype
161+
.value()
162+
.vortex_expect("FieldInfo could not access dtype"),
163+
self.len(),
164+
)
165+
.unwrap_or_else(|e| {
166+
vortex_panic!(e, "StructArray: field {} not found", idx)
167+
})
168+
})
169+
.unwrap_or_else(|e| vortex_panic!(e, "StructArray: field {} not found", idx)),
170+
)
158171
}
159172

160173
fn project(&self, projection: &[Field]) -> VortexResult<ArrayData> {

vortex-array/src/variants.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::sync::Arc;
77

8-
use vortex_dtype::{DType, ExtDType, Field, FieldNames, PType};
8+
use vortex_dtype::{DType, ExtDType, Field, FieldInfo, FieldNames, PType};
99
use vortex_error::{vortex_panic, VortexError, VortexExpect as _, VortexResult};
1010

1111
use crate::encoding::Encoding;
@@ -189,6 +189,14 @@ pub trait StructArrayTrait: ArrayTrait {
189189
st.names()
190190
}
191191

192+
fn field_info(&self, field: &Field) -> VortexResult<FieldInfo> {
193+
let DType::Struct(st, _) = self.dtype() else {
194+
unreachable!()
195+
};
196+
197+
st.field_info(field)
198+
}
199+
192200
fn dtypes(&self) -> Vec<DType> {
193201
let DType::Struct(st, _) = self.dtype() else {
194202
unreachable!()

0 commit comments

Comments
 (0)