pub trait ExprSimplifiable: Sized {
fn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self>;
}Expand description
trait for types that can be simplified
Required Methods
fn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self>
fn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self>
simplify this trait object using the given SimplifyInfo
Implementations on Foreign Types
sourceimpl ExprSimplifiable for Expr
impl ExprSimplifiable for Expr
sourcefn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self>
fn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self>
Simplifies this Expr`s as much as possible, evaluating
constants and applying algebraic simplifications
Example:
b > 2 AND b > 2
can be written to
b > 2
use datafusion_expr::{col, lit, Expr};
use datafusion_common::Result;
use datafusion_physical_expr::execution_props::ExecutionProps;
use datafusion_optimizer::expr_simplifier::{SimplifyInfo, ExprSimplifiable};
/// Simple implementation that provides `Simplifier` the information it needs
#[derive(Default)]
struct Info {
execution_props: ExecutionProps,
};
impl SimplifyInfo for Info {
fn is_boolean_type(&self, expr: &Expr) -> Result<bool> {
Ok(false)
}
fn nullable(&self, expr: &Expr) -> Result<bool> {
Ok(true)
}
fn execution_props(&self) -> &ExecutionProps {
&self.execution_props
}
}
// b < 2
let b_lt_2 = col("b").gt(lit(2));
// (b < 2) OR (b < 2)
let expr = b_lt_2.clone().or(b_lt_2.clone());
// (b < 2) OR (b < 2) --> (b < 2)
let expr = expr.simplify(&Info::default()).unwrap();
assert_eq!(expr, b_lt_2);