Skip to content

Commit

Permalink
Merge branch 'develop' into ji/traverse-expr
Browse files Browse the repository at this point in the history
# Conflicts:
#	vortex-expr/src/binary.rs
#	vortex-expr/src/like.rs
#	vortex-expr/src/not.rs
#	vortex-expr/src/project.rs
#	vortex-expr/src/pruning.rs
  • Loading branch information
joseph-isaacs committed Jan 7, 2025
1 parent 9b80201 commit 4a9ea25
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion vortex-datafusion/src/memory/plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use vortex_array::compute::take;
use vortex_array::{ArrayData, IntoArrayVariant, IntoCanonical};
use vortex_dtype::Field;
use vortex_error::{vortex_err, vortex_panic, VortexError};
use vortex_expr::ExprRef;
use vortex_expr::{ExprRef, VortexExprExt};

/// Physical plan operator that applies a set of [filters][Expr] against the input, producing a
/// row mask that can be used downstream to force a take against the corresponding struct array
Expand Down
7 changes: 4 additions & 3 deletions vortex-expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use select::*;
use vortex_array::aliases::hash_set::HashSet;
use vortex_array::ArrayData;
use vortex_dtype::Field;
use vortex_error::{VortexExpect, VortexResult};
use vortex_error::{VortexExpect, VortexResult, VortexUnwrap};

use crate::traversal::{Node, ReferenceCollector};

Expand All @@ -49,14 +49,15 @@ pub trait VortexExpr: Debug + Send + Sync + PartialEq<dyn Any> + Display {
fn replacing_children(self: Arc<Self>, children: Vec<ExprRef>) -> ExprRef;
}

trait VortexExprExt {
pub trait VortexExprExt {
fn references(&self) -> HashSet<&Field>;
}

impl VortexExprExt for ExprRef {
fn references(&self) -> HashSet<&Field> {
let mut collector = ReferenceCollector::new();
self.accept(&mut collector).unwrap();
// The collector is infallible, so we can unwrap the result
self.accept(&mut collector).vortex_unwrap();
collector.into_fields()
}
}
Expand Down
6 changes: 4 additions & 2 deletions vortex-expr/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub struct Literal {
}

impl Literal {
pub fn new_expr(value: Scalar) -> ExprRef {
Arc::new(Self { value })
pub fn new_expr(value: impl Into<Scalar>) -> ExprRef {
Arc::new(Self {
value: value.into(),
})
}

pub fn value(&self) -> &Scalar {
Expand Down
10 changes: 5 additions & 5 deletions vortex-expr/src/traversal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ mod tests {
let id = self.0;
self.0 += 1;
Ok(TransformResult {
result: Literal::new_expr(id.into()).into(),
result: Literal::new_expr(id),
order: VisitationOrder::Continue,
changed: true,
})
Expand All @@ -197,9 +197,9 @@ mod tests {
#[test]
fn expr_deep_visitor_test() {
let col1: Arc<dyn VortexExpr> = Column::new_expr("col1");
let lit1 = Literal::new_expr(1.into());
let lit1 = Literal::new_expr(1);
let expr = BinaryExpr::new_expr(col1.clone(), Operator::Eq, lit1.clone());
let lit2 = Literal::new_expr(2.into());
let lit2 = Literal::new_expr(2);
let expr = BinaryExpr::new_expr(expr, Operator::And, lit2);
let mut printer = ExprCollector::default();
expr.accept(&mut printer).unwrap();
Expand All @@ -211,11 +211,11 @@ mod tests {
let col1: Arc<dyn VortexExpr> = Column::new_expr("col1");
let col2: Arc<dyn VortexExpr> = Column::new_expr("col2");
let expr = BinaryExpr::new_expr(col1.clone(), Operator::Eq, col2.clone());
let lit2 = Literal::new_expr(2.into());
let lit2 = Literal::new_expr(2);
let expr = BinaryExpr::new_expr(expr, Operator::And, lit2);
let mut printer = ExprColToLit::default();
let new = expr.transform(&mut printer).unwrap();
assert_eq!(new.changed, true);
assert!(new.changed);

let expr = new.result;

Expand Down
2 changes: 1 addition & 1 deletion vortex-file/src/read/layouts/columnar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use vortex_array::validity::Validity;
use vortex_array::{ArrayData, IntoArrayData};
use vortex_dtype::{Field, FieldName, FieldNames};
use vortex_error::{vortex_bail, vortex_err, vortex_panic, VortexExpect, VortexResult};
use vortex_expr::{col, expr_project, RowFilter, Select, VortexExpr};
use vortex_expr::{col, expr_project, RowFilter, Select, VortexExpr, VortexExprExt};
use vortex_flatbuffers::footer;

use crate::read::cache::LazyDType;
Expand Down

0 comments on commit 4a9ea25

Please sign in to comment.