pub struct ExprIntervalGraph { /* private fields */ }
Expand description
This object implements a directed acyclic expression graph (DAEG) that is used to compute ranges for expressions through interval arithmetic.
Implementations§
source§impl ExprIntervalGraph
impl ExprIntervalGraph
pub fn try_new(expr: Arc<dyn PhysicalExpr>, schema: &Schema) -> Result<Self>
pub fn node_count(&self) -> usize
sourcepub fn gather_node_indices(
&mut self,
exprs: &[Arc<dyn PhysicalExpr>],
) -> Vec<(Arc<dyn PhysicalExpr>, usize)>
pub fn gather_node_indices( &mut self, exprs: &[Arc<dyn PhysicalExpr>], ) -> Vec<(Arc<dyn PhysicalExpr>, usize)>
This function associates stable node indices with PhysicalExpr
s so
that we can match Arc<dyn PhysicalExpr>
and NodeIndex objects during
membership tests.
sourcepub fn update_ranges(
&mut self,
leaf_bounds: &mut [(usize, Interval)],
given_range: Interval,
) -> Result<PropagationResult>
pub fn update_ranges( &mut self, leaf_bounds: &mut [(usize, Interval)], given_range: Interval, ) -> Result<PropagationResult>
Updates intervals for all expressions in the DAEG by successive bottom-up and top-down traversals.
sourcepub fn assign_intervals(&mut self, assignments: &[(usize, Interval)])
pub fn assign_intervals(&mut self, assignments: &[(usize, Interval)])
This function assigns given ranges to expressions in the DAEG.
The argument assignments
associates indices of sought expressions
with their corresponding new ranges.
sourcepub fn update_intervals(&self, assignments: &mut [(usize, Interval)])
pub fn update_intervals(&self, assignments: &mut [(usize, Interval)])
This function fetches ranges of expressions from the DAEG. The argument
assignments
associates indices of sought expressions with their ranges,
which this function modifies to reflect the intervals in the DAEG.
sourcepub fn evaluate_bounds(&mut self) -> Result<&Interval>
pub fn evaluate_bounds(&mut self) -> Result<&Interval>
Computes bounds for an expression using interval arithmetic via a bottom-up traversal.
§Arguments
leaf_bounds
- &[(usize, Interval)]. Provide NodeIndex, Interval tuples for leaf variables.
§Examples
use arrow::datatypes::DataType;
use arrow::datatypes::Field;
use arrow::datatypes::Schema;
use datafusion_common::ScalarValue;
use datafusion_expr::interval_arithmetic::Interval;
use datafusion_expr::Operator;
use datafusion_physical_expr::expressions::{BinaryExpr, Column, Literal};
use datafusion_physical_expr::intervals::cp_solver::ExprIntervalGraph;
use datafusion_physical_expr::PhysicalExpr;
use std::sync::Arc;
let expr = Arc::new(BinaryExpr::new(
Arc::new(Column::new("gnz", 0)),
Operator::Plus,
Arc::new(Literal::new(ScalarValue::Int32(Some(10)))),
));
let schema = Schema::new(vec![Field::new("gnz".to_string(), DataType::Int32, true)]);
let mut graph = ExprIntervalGraph::try_new(expr, &schema).unwrap();
// Do it once, while constructing.
let node_indices = graph
.gather_node_indices(&[Arc::new(Column::new("gnz", 0))]);
let left_index = node_indices.get(0).unwrap().1;
// Provide intervals for leaf variables (here, there is only one).
let intervals = vec![(
left_index,
Interval::make(Some(10), Some(20)).unwrap(),
)];
// Evaluate bounds for the composite expression:
graph.assign_intervals(&intervals);
assert_eq!(
graph.evaluate_bounds().unwrap(),
&Interval::make(Some(20), Some(30)).unwrap(),
)
sourcepub fn get_interval(&self, index: usize) -> Interval
pub fn get_interval(&self, index: usize) -> Interval
Returns the interval associated with the node at the given index
.
Trait Implementations§
source§impl Clone for ExprIntervalGraph
impl Clone for ExprIntervalGraph
source§fn clone(&self) -> ExprIntervalGraph
fn clone(&self) -> ExprIntervalGraph
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ExprIntervalGraph
impl !RefUnwindSafe for ExprIntervalGraph
impl Send for ExprIntervalGraph
impl Sync for ExprIntervalGraph
impl Unpin for ExprIntervalGraph
impl !UnwindSafe for ExprIntervalGraph
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more