Skip to content

Commit d75003a

Browse files
Add an AccessPath (Identity + FieldPath) (#3476)
Signed-off-by: Joe Isaacs <[email protected]> --------- Signed-off-by: Joe Isaacs <[email protected]> Signed-off-by: Adam Gutglick <[email protected]> Co-authored-by: Adam Gutglick <[email protected]>
1 parent 5f0ece7 commit d75003a

File tree

12 files changed

+197
-159
lines changed

12 files changed

+197
-159
lines changed

vortex-dtype/src/field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ impl Field {
6262
/// A path through a (possibly nested) struct, composed of a sequence of field selectors
6363
// TODO(ngates): we should probably reverse the path. Or better yet, store a Arc<[Field]> along
6464
// with a positional index to allow cheap step_into.
65-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
65+
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
6666
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6767
pub struct FieldPath(Vec<Field>);
6868

6969
impl FieldPath {
7070
/// The selector for the root (i.e., the top-level struct itself)
7171
pub fn root() -> Self {
72-
Self(vec![])
72+
Self::default()
7373
}
7474

7575
/// Constructs a new `FieldPath` from a single field selector (i.e., a direct child field of the top-level struct)

vortex-expr/src/analysis.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use vortex_array::stats::Stat;
2-
use vortex_dtype::FieldPath;
32

4-
use crate::{ExprRef, Identifier};
3+
use crate::{AccessPath, ExprRef};
54

65
pub trait StatsCatalog {
76
/// Given an id, field and stat return an expression that when evaluated will return that stat
87
/// this would be a column reference or a literal value, if the value is known at planning time.
9-
fn stats_ref(&mut self, _id: &Identifier, _field: &FieldPath, _stat: Stat) -> Option<ExprRef> {
8+
fn stats_ref(&mut self, _access_path: &AccessPath, _stat: Stat) -> Option<ExprRef> {
109
None
1110
}
1211
}
@@ -45,7 +44,7 @@ pub trait AnalysisExpr {
4544
None
4645
}
4746

48-
fn field_path(&self) -> Option<(Identifier, FieldPath)> {
47+
fn field_path(&self) -> Option<AccessPath> {
4948
None
5049
}
5150

vortex-expr/src/get_item.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::sync::Arc;
55

66
use vortex_array::stats::Stat;
77
use vortex_array::{ArrayRef, ToCanonical};
8-
use vortex_dtype::{DType, FieldName, FieldPath};
8+
use vortex_dtype::{DType, FieldName};
99
use vortex_error::{VortexResult, vortex_err};
1010

11-
use crate::{AnalysisExpr, ExprRef, Identifier, Scope, ScopeDType, StatsCatalog, VortexExpr, root};
11+
use crate::{AccessPath, AnalysisExpr, ExprRef, Scope, ScopeDType, StatsCatalog, VortexExpr, root};
1212

1313
#[derive(Debug, Clone, Eq, Hash)]
1414
#[allow(clippy::derived_hash_with_manual_eq)]
@@ -97,19 +97,17 @@ pub(crate) mod proto {
9797

9898
impl AnalysisExpr for GetItem {
9999
fn max(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
100-
let (var, path) = self.field_path()?;
101-
catalog.stats_ref(&var, &path, Stat::Max)
100+
catalog.stats_ref(&self.field_path()?, Stat::Max)
102101
}
103102

104103
fn min(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
105-
let (var, path) = self.field_path()?;
106-
catalog.stats_ref(&var, &path, Stat::Min)
104+
catalog.stats_ref(&self.field_path()?, Stat::Min)
107105
}
108106

109-
fn field_path(&self) -> Option<(Identifier, FieldPath)> {
107+
fn field_path(&self) -> Option<AccessPath> {
110108
self.child()
111109
.field_path()
112-
.map(|(var, fp)| (var, fp.push(self.field())))
110+
.map(|fp| AccessPath::new(fp.field_path.push(self.field.clone()), fp.identifier))
113111
}
114112
}
115113

vortex-expr/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub use select::*;
5353
pub use var::*;
5454
use vortex_array::aliases::hash_set::HashSet;
5555
use vortex_array::{Array, ArrayRef};
56-
use vortex_dtype::{DType, FieldName};
56+
use vortex_dtype::{DType, FieldName, FieldPath};
5757
use vortex_error::{VortexResult, VortexUnwrap};
5858
#[cfg(feature = "proto")]
5959
use vortex_proto::expr;
@@ -155,6 +155,36 @@ impl VortexExprExt for ExprRef {
155155
}
156156
}
157157

158+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
159+
pub struct AccessPath {
160+
field_path: FieldPath,
161+
identifier: Identifier,
162+
}
163+
164+
impl AccessPath {
165+
pub fn root_field(path: FieldName) -> Self {
166+
Self {
167+
field_path: FieldPath::from_name(path),
168+
identifier: Identifier::Identity,
169+
}
170+
}
171+
172+
fn new(path: FieldPath, identifier: Identifier) -> Self {
173+
Self {
174+
field_path: path,
175+
identifier,
176+
}
177+
}
178+
179+
pub fn identifier(&self) -> &Identifier {
180+
&self.identifier
181+
}
182+
183+
pub fn field_path(&self) -> &FieldPath {
184+
&self.field_path
185+
}
186+
}
187+
158188
/// Splits top level and operations into separate expressions
159189
pub fn split_conjunction(expr: &ExprRef) -> Vec<ExprRef> {
160190
let mut conjunctions = vec![];

vortex-expr/src/pruning/field_or_identity.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

vortex-expr/src/pruning/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
mod field_or_identity;
21
mod pruning_predicate;
32
mod relation;
43

5-
pub use field_or_identity::{FieldOrIdentity, stat_field_name};
6-
pub use pruning_predicate::PruningPredicate;
4+
pub use pruning_predicate::{PruningPredicate, access_path_stat_field_name};

0 commit comments

Comments
 (0)