pub enum ApplyOrder {
TopDown,
BottomUp,
}
Expand description
If a rule is with ApplyOrder
, it means the optimizer will derive to handle children instead of
recursively handling in rule.
We just need handle a subtree pattern itself.
Notice: sometime result after optimize still can be optimized, we need apply again.
Usage Example: Merge Limit (subtree pattern is: Limit-Limit)
use datafusion_expr::{Limit, LogicalPlan, LogicalPlanBuilder};
use datafusion_common::Result;
fn merge_limit(parent: &Limit, child: &Limit) -> LogicalPlan {
// just for run
return parent.input.as_ref().clone();
}
fn try_optimize(plan: &LogicalPlan) -> Result<Option<LogicalPlan>> {
match plan {
LogicalPlan::Limit(limit) => match limit.input.as_ref() {
LogicalPlan::Limit(child_limit) => {
// merge limit ...
let optimized_plan = merge_limit(limit, child_limit);
// due to optimized_plan may be optimized again,
// for example: plan is Limit-Limit-Limit
Ok(Some(
try_optimize(&optimized_plan)?
.unwrap_or_else(|| optimized_plan.clone()),
))
}
_ => Ok(None),
},
_ => Ok(None),
}
}
Variants§
Auto Trait Implementations§
impl RefUnwindSafe for ApplyOrder
impl Send for ApplyOrder
impl Sync for ApplyOrder
impl Unpin for ApplyOrder
impl UnwindSafe for ApplyOrder
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