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>

source

pub fn new(props: &'a ExecutionProps) -> Self

Create a new SimplifyContext

source

pub fn with_schema(self, schema: DFSchemaRef) -> Self

Register a DFSchemaRef with this context

Trait Implementations§

source§

impl<'a> SimplifyInfo for SimplifyContext<'a>

source§

fn is_boolean_type(&self, expr: &Expr) -> Result<bool>

returns true if this Expr has boolean type

source§

fn nullable(&self, expr: &Expr) -> Result<bool>

Returns true if expr is nullable

source§

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

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V