vortex_layout/plan/physical/optimizer/
mod.rs1mod rules;
7
8pub use rules::DynPlanParentReduceRule;
9pub use rules::DynPlanReduceRule;
10pub use rules::PlanParentReduceRule;
11pub use rules::PlanParentReduceRuleAdapter;
12pub use rules::PlanParentRuleSet;
13pub use rules::PlanReduceRule;
14pub use rules::PlanReduceRuleAdapter;
15pub use rules::PlanRuleSet;
16use vortex_error::VortexResult;
17
18use super::Concat;
19use super::Eval;
20use super::LegacyStats;
21use super::Pack;
22use super::PlanRef;
23use super::Take;
24use super::Zoned;
25use super::plans::EvalIdentityRule;
26use super::plans::ExpressionConcatRule;
27use super::plans::ExpressionPackRule;
28use super::plans::ExpressionTakeRule;
29use super::plans::ExpressionZonedRule;
30use super::plans::LegacyStatsRule;
31use super::plans::ZonedLegacyStatsRule;
32
33static EVAL_IDENTITY_RULE: PlanReduceRuleAdapter<Eval, EvalIdentityRule> =
34 PlanReduceRuleAdapter::new(EvalIdentityRule);
35
36static LEGACY_STATS_RULE: PlanReduceRuleAdapter<LegacyStats, LegacyStatsRule> =
37 PlanReduceRuleAdapter::new(LegacyStatsRule);
38
39static PLAN_RULES: PlanRuleSet = PlanRuleSet::new(&[&EVAL_IDENTITY_RULE, &LEGACY_STATS_RULE]);
40
41static EXPRESSION_CONCAT_RULE: PlanParentReduceRuleAdapter<Concat, ExpressionConcatRule> =
42 PlanParentReduceRuleAdapter::new(ExpressionConcatRule);
43static EXPRESSION_TAKE_RULE: PlanParentReduceRuleAdapter<Take, ExpressionTakeRule> =
44 PlanParentReduceRuleAdapter::new(ExpressionTakeRule);
45static EXPRESSION_PACK_RULE: PlanParentReduceRuleAdapter<Pack, ExpressionPackRule> =
46 PlanParentReduceRuleAdapter::new(ExpressionPackRule);
47static EXPRESSION_ZONED_RULE: PlanParentReduceRuleAdapter<Zoned, ExpressionZonedRule> =
48 PlanParentReduceRuleAdapter::new(ExpressionZonedRule);
49
50static ZONED_LEGACY_STATS_RULE: PlanParentReduceRuleAdapter<LegacyStats, ZonedLegacyStatsRule> =
51 PlanParentReduceRuleAdapter::new(ZonedLegacyStatsRule);
52
53static PARENT_RULES: PlanParentRuleSet = PlanParentRuleSet::new(&[
54 &EXPRESSION_CONCAT_RULE,
55 &EXPRESSION_TAKE_RULE,
56 &EXPRESSION_PACK_RULE,
57 &EXPRESSION_ZONED_RULE,
58 &ZONED_LEGACY_STATS_RULE,
59]);
60
61pub(crate) fn reduce_plan(plan: &PlanRef) -> VortexResult<Option<PlanRef>> {
63 PLAN_RULES.evaluate(plan)
64}
65
66pub(crate) fn reduce_parent(parent: &PlanRef, child_idx: usize) -> VortexResult<Option<PlanRef>> {
68 let Some(child) = parent.children().get_ref(child_idx)? else {
69 return Ok(None);
70 };
71 PARENT_RULES.evaluate(child, parent, child_idx)
72}