pub struct SimplifyContext<'a> { /* private fields */ }
Expand description
Provides simplification information based on DFSchema and
ExecutionProps
. This is the default implementation used by DataFusion
For example:
use arrow::datatypes::{Schema, Field, DataType};
use datafusion_expr::{col, lit};
use datafusion_common::{DataFusionError, ToDFSchema};
use datafusion_physical_expr::execution_props::ExecutionProps;
use datafusion_optimizer::simplify_expressions::{SimplifyContext, ExprSimplifier};
// Create the schema
let schema = Schema::new(vec![
Field::new("i", DataType::Int64, false),
])
.to_dfschema_ref().unwrap();
// Create the simplifier
let props = ExecutionProps::new();
let context = SimplifyContext::new(&props)
.with_schema(schema);
let simplifier = ExprSimplifier::new(context);
// Use the simplifier
// b < 2 or (1 > 3)
let expr = col("b").lt(lit(2)).or(lit(1).gt(lit(3)));
// b < 2
let simplified = simplifier.simplify(expr).unwrap();
assert_eq!(simplified, col("b").lt(lit(2)));
Implementations§
source§impl<'a> SimplifyContext<'a>
impl<'a> SimplifyContext<'a>
sourcepub fn new(props: &'a ExecutionProps) -> Self
pub fn new(props: &'a ExecutionProps) -> Self
Create a new SimplifyContext
sourcepub fn with_schema(self, schema: DFSchemaRef) -> Self
pub fn with_schema(self, schema: DFSchemaRef) -> Self
Register a DFSchemaRef
with this context
Trait Implementations§
source§impl<'a> SimplifyInfo for SimplifyContext<'a>
impl<'a> SimplifyInfo for SimplifyContext<'a>
source§fn is_boolean_type(&self, expr: &Expr) -> Result<bool>
fn is_boolean_type(&self, expr: &Expr) -> Result<bool>
returns true if this Expr has boolean type
source§fn get_data_type(&self, expr: &Expr) -> Result<DataType>
fn get_data_type(&self, expr: &Expr) -> Result<DataType>
Returns data type of this expr needed for determining optimized int type of a value
source§fn execution_props(&self) -> &ExecutionProps
fn execution_props(&self) -> &ExecutionProps
Returns details needed for partial expression evaluation
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for SimplifyContext<'a>
impl<'a> Send for SimplifyContext<'a>
impl<'a> Sync for SimplifyContext<'a>
impl<'a> Unpin for SimplifyContext<'a>
impl<'a> !UnwindSafe for SimplifyContext<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more