Skip to content

Commit

Permalink
Remove field from struct layout (#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-isaacs authored Jan 13, 2025
1 parent 86b6ab4 commit 0c2b023
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions vortex-layout/src/layouts/struct_/eval_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use itertools::Itertools;
use vortex_array::array::StructArray;
use vortex_array::validity::Validity;
use vortex_array::{ArrayData, IntoArrayData};
use vortex_dtype::Field;
use vortex_error::VortexResult;
use vortex_expr::transform::partition::partition;
use vortex_expr::ExprRef;
Expand All @@ -22,7 +21,7 @@ impl ExprEvaluator for StructReader {
.partitions
.iter()
// TODO(joe): remove field from self.child
.map(|partition| self.child(&Field::Name(partition.name.clone())))
.map(|partition| self.child(&partition.name.clone()))
.try_collect()?;

let arrays = try_join_all(
Expand Down
17 changes: 8 additions & 9 deletions vortex-layout/src/layouts/struct_/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::{Arc, OnceLock};

use vortex_array::aliases::hash_map::HashMap;
use vortex_array::ContextRef;
use vortex_dtype::{DType, Field, FieldName, StructDType};
use vortex_dtype::{DType, FieldName, StructDType};
use vortex_error::{vortex_err, vortex_panic, VortexExpect, VortexResult};

use crate::layouts::struct_::StructLayout;
Expand Down Expand Up @@ -63,14 +63,13 @@ impl StructReader {
}

/// Return the child reader for the chunk.
pub(crate) fn child(&self, field: &Field) -> VortexResult<&Arc<dyn LayoutReader>> {
let idx = match field {
Field::Name(n) => *self
.field_lookup
.get(n)
.ok_or_else(|| vortex_err!("Field {} not found in struct layout", n))?,
Field::Index(idx) => *idx,
};
pub(crate) fn child(&self, name: &FieldName) -> VortexResult<&Arc<dyn LayoutReader>> {
let idx = *self
.field_lookup
.get(name)
.ok_or_else(|| vortex_err!("Field {} not found in struct layout", name))?;

// TODO: think about a hashmap for large |fields|.
self.field_readers[idx].get_or_try_init(|| {
let child_layout = self
.layout
Expand Down

0 comments on commit 0c2b023

Please sign in to comment.