Skip to content

Commit b1dbfe7

Browse files
Rescope expression then the identity is a struct dtype (#1887)
Defines a transform on expression with an scope type of struct(..). The transform splits the expr in to a series of expressions that can be evaluated only using a single field of the struct, and a combination expr which combines the series of smaller expr into the original expr. This is used #1893. --------- Co-authored-by: Nicholas Gates <[email protected]>
1 parent f61f3ba commit b1dbfe7

File tree

8 files changed

+606
-7
lines changed

8 files changed

+606
-7
lines changed

vortex-expr/src/forms/nnf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use vortex_error::VortexResult;
22

3-
use crate::traversal::{FoldChildren, FoldDown, FoldUp, Folder, Node as _};
3+
use crate::traversal::{FoldChildren, FoldDown, FoldUp, FolderMut, Node as _};
44
use crate::{not, BinaryExpr, ExprRef, Not, Operator};
55

66
/// Return an equivalent expression in Negative Normal Form (NNF).
@@ -63,7 +63,7 @@ pub fn nnf(expr: ExprRef) -> VortexResult<ExprRef> {
6363
#[derive(Default)]
6464
struct NNFVisitor {}
6565

66-
impl Folder for NNFVisitor {
66+
impl FolderMut for NNFVisitor {
6767
type NodeTy = ExprRef;
6868
type Out = ExprRef;
6969
type Context = bool;

vortex-expr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod project;
1919
pub mod pruning;
2020
mod row_filter;
2121
mod select;
22+
pub mod transform;
2223
#[allow(dead_code)]
2324
mod traversal;
2425

vortex-expr/src/pack.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use itertools::Itertools as _;
77
use vortex_array::array::StructArray;
88
use vortex_array::validity::Validity;
99
use vortex_array::{ArrayData, IntoArrayData};
10-
use vortex_dtype::FieldNames;
11-
use vortex_error::{vortex_bail, VortexExpect as _, VortexResult};
10+
use vortex_dtype::{Field, FieldNames};
11+
use vortex_error::{vortex_bail, vortex_err, VortexExpect as _, VortexResult};
1212

1313
use crate::{ExprRef, VortexExpr};
1414

@@ -51,6 +51,33 @@ impl Pack {
5151
}
5252
Ok(Arc::new(Pack { names, values }))
5353
}
54+
55+
pub fn names(&self) -> &FieldNames {
56+
&self.names
57+
}
58+
59+
pub fn field(&self, f: &Field) -> VortexResult<ExprRef> {
60+
let idx = match f {
61+
Field::Name(n) => self
62+
.names
63+
.iter()
64+
.position(|name| name == n)
65+
.ok_or_else(|| {
66+
vortex_err!("Cannot find field {} in pack fields {:?}", n, self.names)
67+
})?,
68+
Field::Index(idx) => *idx,
69+
};
70+
71+
self.values
72+
.get(idx)
73+
.cloned()
74+
.ok_or_else(|| vortex_err!("field index out of bounds: {}", idx))
75+
}
76+
}
77+
78+
pub fn pack(names: impl Into<FieldNames>, values: Vec<ExprRef>) -> ExprRef {
79+
Pack::try_new_expr(names.into(), values)
80+
.vortex_expect("pack names and values have the same length")
5481
}
5582

5683
impl PartialEq<dyn Any> for Pack {

vortex-expr/src/select.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ pub struct Select {
2323
child: ExprRef,
2424
}
2525

26+
pub fn select(fields: Vec<Field>, child: ExprRef) -> ExprRef {
27+
Select::include_expr(fields, child)
28+
}
29+
30+
pub fn select_exclude(columns: Vec<Field>, child: ExprRef) -> ExprRef {
31+
Select::exclude_expr(columns, child)
32+
}
33+
2634
impl Select {
2735
pub fn new_expr(fields: SelectField, child: ExprRef) -> ExprRef {
2836
Arc::new(Self { fields, child })

vortex-expr/src/transform/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod partition;
2+
pub mod simplify;

0 commit comments

Comments
 (0)