Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescope expression then the identity is a struct dtype #1887

Merged
merged 25 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vortex-expr/src/forms/nnf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use vortex_error::VortexResult;

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

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

impl Folder for NNFVisitor {
impl FolderMut for NNFVisitor {
type NodeTy = ExprRef;
type Out = ExprRef;
type Context = bool;
Expand Down
1 change: 1 addition & 0 deletions vortex-expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod project;
pub mod pruning;
mod row_filter;
mod select;
pub mod transform;
#[allow(dead_code)]
mod traversal;

Expand Down
31 changes: 29 additions & 2 deletions vortex-expr/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use itertools::Itertools as _;
use vortex_array::array::StructArray;
use vortex_array::validity::Validity;
use vortex_array::{ArrayData, IntoArrayData};
use vortex_dtype::FieldNames;
use vortex_error::{vortex_bail, VortexExpect as _, VortexResult};
use vortex_dtype::{Field, FieldNames};
use vortex_error::{vortex_bail, vortex_err, VortexExpect as _, VortexResult};

use crate::{ExprRef, VortexExpr};

Expand Down Expand Up @@ -51,6 +51,33 @@ impl Pack {
}
Ok(Arc::new(Pack { names, values }))
}

pub fn names(&self) -> &FieldNames {
&self.names
}

pub fn field(&self, f: &Field) -> VortexResult<ExprRef> {
let idx = match f {
Field::Name(n) => self
.names
.iter()
.position(|name| name == n)
.ok_or_else(|| {
vortex_err!("Cannot find field {} in pack fields {:?}", n, self.names)
})?,
Field::Index(idx) => *idx,
};

self.values
.get(idx)
.cloned()
.ok_or_else(|| vortex_err!("field index out of bounds: {}", idx))
}
}

pub fn pack(names: impl Into<FieldNames>, values: Vec<ExprRef>) -> ExprRef {
Pack::try_new_expr(names.into(), values)
.vortex_expect("pack names and values have the same length")
}

impl PartialEq<dyn Any> for Pack {
Expand Down
8 changes: 8 additions & 0 deletions vortex-expr/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct Select {
child: ExprRef,
}

pub fn select(fields: Vec<Field>, child: ExprRef) -> ExprRef {
Select::include_expr(fields, child)
}

pub fn select_exclude(columns: Vec<Field>, child: ExprRef) -> ExprRef {
Select::exclude_expr(columns, child)
}

impl Select {
pub fn new_expr(fields: SelectField, child: ExprRef) -> ExprRef {
Arc::new(Self { fields, child })
Expand Down
2 changes: 2 additions & 0 deletions vortex-expr/src/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod partition;
pub mod simplify;
Loading
Loading