Skip to content

Commit

Permalink
Merge branch 'develop' into adamg/structured_fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGS committed Aug 15, 2024
2 parents 47b2283 + eea0264 commit d6e4899
Showing 1 changed file with 2 additions and 57 deletions.
59 changes: 2 additions & 57 deletions vortex-datafusion/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ use std::fmt::Debug;
use std::sync::Arc;

use arrow_schema::{Schema, SchemaRef};
use datafusion::optimizer::simplify_expressions::ExprSimplifier;
use datafusion_common::tree_node::{TreeNode, TreeNodeRecursion};
use datafusion_common::{DataFusionError, Result as DFResult, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::{and, lit, Expr, Operator as DFOperator};
use datafusion_common::{DataFusionError, Result as DFResult};
use datafusion_expr::Operator as DFOperator;
use datafusion_physical_expr::PhysicalExpr;
use vortex::array::{ConstantArray, StructArray};
use vortex::compute::compare;
Expand All @@ -22,33 +19,6 @@ use vortex_scalar::Scalar;

use crate::scalar::dfvalue_to_scalar;

/// Convert a set of expressions into a single AND expression.
///
/// # Returns
///
/// If conversion is successful, the result will be a
/// [binary expression node][datafusion_expr::Expr::BinaryExpr] containing the conjunction.
pub(crate) fn make_conjunction(exprs: impl AsRef<[Expr]>) -> DFResult<Expr> {
Ok(exprs
.as_ref()
.iter()
.fold(lit(true), |conj, elem| and(conj, elem.clone())))
}

/// Simplify an expression using DataFusion's builtin analysis passes.
///
/// This encapsulates common optimizations like constant folding and eliminating redundant
/// expressions, e.g. `value AND true`.
pub(crate) fn simplify_expr(expr: &Expr, schema: SchemaRef) -> DFResult<Expr> {
let schema = schema.to_dfschema_ref()?;

let props = ExecutionProps::new();
let context = SimplifyContext::new(&props).with_schema(schema);
let simplifier = ExprSimplifier::new(context);

simplifier.simplify(expr.clone())
}

pub trait VortexPhysicalExpr: Debug + Send + Sync {
fn evaluate(&self, array: &Array) -> VortexResult<Array>;
}
Expand Down Expand Up @@ -206,28 +176,3 @@ pub(crate) fn extract_columns_from_expr(

Ok(predicate_projection)
}

#[cfg(test)]
mod test {
use std::sync::Arc;

use arrow_schema::{DataType, Field, Schema};
use datafusion_expr::{col, lit};

use super::*;

#[test]
fn test_conjunction_simplify() {
let schema = Arc::new(Schema::new(vec![
Field::new("int_col", DataType::Int32, false),
Field::new("bool_col", DataType::Boolean, false),
]));

let exprs = vec![col("int_col").gt_eq(lit(4)), col("bool_col").is_true()];

assert_eq!(
simplify_expr(&make_conjunction(&exprs).unwrap(), schema).unwrap(),
and(col("int_col").gt_eq(lit(4)), col("bool_col").is_true())
);
}
}

0 comments on commit d6e4899

Please sign in to comment.