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>) -> 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 PhysicalExprs so
that we can match Arc<dyn PhysicalExpr>
and NodeIndex objects during
membership tests.
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 std::sync::Arc;
use datafusion_common::ScalarValue;
use datafusion_expr::Operator;
use datafusion_physical_expr::expressions::{BinaryExpr, Column, Literal};
use datafusion_physical_expr::intervals::{Interval, IntervalBound, ExprIntervalGraph};
use datafusion_physical_expr::PhysicalExpr;
let expr = Arc::new(BinaryExpr::new(
Arc::new(Column::new("gnz", 0)),
Operator::Plus,
Arc::new(Literal::new(ScalarValue::Int32(Some(10)))),
));
let mut graph = ExprIntervalGraph::try_new(expr).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), (true, true)),
)];
// Evaluate bounds for the composite expression:
graph.assign_intervals(&intervals);
assert_eq!(
graph.evaluate_bounds().unwrap(),
&Interval::make(Some(20), Some(30), (true, true)),
)
sourcepub fn update_ranges(
&mut self,
leaf_bounds: &mut [(usize, Interval)]
) -> Result<PropagationResult>
pub fn update_ranges( &mut self, leaf_bounds: &mut [(usize, Interval)] ) -> Result<PropagationResult>
Updates intervals for all expressions in the DAEG by successive bottom-up and top-down traversals.
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 more