diff --git a/src/frontend/src/optimizer/plan_rewriter/share_source_rewriter.rs b/src/frontend/src/optimizer/plan_rewriter/share_source_rewriter.rs index db7ecd92c7aa5..9ab0d4d580ddc 100644 --- a/src/frontend/src/optimizer/plan_rewriter/share_source_rewriter.rs +++ b/src/frontend/src/optimizer/plan_rewriter/share_source_rewriter.rs @@ -109,8 +109,10 @@ impl PlanRewriter for ShareSourceRewriter { } } -impl PlanVisitor<()> for SourceCounter { - type DefaultBehavior = impl DefaultBehavior<()>; +impl PlanVisitor for SourceCounter { + type Result = (); + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { DefaultValue diff --git a/src/frontend/src/optimizer/plan_visitor/cardinality_visitor.rs b/src/frontend/src/optimizer/plan_visitor/cardinality_visitor.rs index 3b071ddaf3dfe..a9eb5639fcf85 100644 --- a/src/frontend/src/optimizer/plan_visitor/cardinality_visitor.rs +++ b/src/frontend/src/optimizer/plan_visitor/cardinality_visitor.rs @@ -83,8 +83,10 @@ impl CardinalityVisitor { } } -impl PlanVisitor for CardinalityVisitor { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for CardinalityVisitor { + type Result = Cardinality; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { // returns unknown cardinality for default behavior, which is always correct diff --git a/src/frontend/src/optimizer/plan_visitor/execution_mode_decider.rs b/src/frontend/src/optimizer/plan_visitor/execution_mode_decider.rs index f1f3d4edfdc74..6eb7f7def64aa 100644 --- a/src/frontend/src/optimizer/plan_visitor/execution_mode_decider.rs +++ b/src/frontend/src/optimizer/plan_visitor/execution_mode_decider.rs @@ -28,8 +28,10 @@ impl ExecutionModeDecider { } } -impl PlanVisitor for ExecutionModeDecider { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for ExecutionModeDecider { + type Result = bool; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a & b) diff --git a/src/frontend/src/optimizer/plan_visitor/input_ref_validator.rs b/src/frontend/src/optimizer/plan_visitor/input_ref_validator.rs index a8e48633d6a31..6911c6e8ce89a 100644 --- a/src/frontend/src/optimizer/plan_visitor/input_ref_validator.rs +++ b/src/frontend/src/optimizer/plan_visitor/input_ref_validator.rs @@ -103,8 +103,10 @@ macro_rules! visit_project { }; } -impl PlanVisitor> for InputRefValidator { - type DefaultBehavior = impl DefaultBehavior>; +impl PlanVisitor for InputRefValidator { + type Result = Option; + + type DefaultBehavior = impl DefaultBehavior; visit_filter!(logical, batch, stream); diff --git a/src/frontend/src/optimizer/plan_visitor/max_one_row_visitor.rs b/src/frontend/src/optimizer/plan_visitor/max_one_row_visitor.rs index 32a6c874efe40..2a3a354674621 100644 --- a/src/frontend/src/optimizer/plan_visitor/max_one_row_visitor.rs +++ b/src/frontend/src/optimizer/plan_visitor/max_one_row_visitor.rs @@ -18,8 +18,10 @@ use crate::optimizer::plan_visitor::PlanVisitor; pub struct HasMaxOneRowApply(); -impl PlanVisitor for HasMaxOneRowApply { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for HasMaxOneRowApply { + type Result = bool; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a | b) diff --git a/src/frontend/src/optimizer/plan_visitor/mod.rs b/src/frontend/src/optimizer/plan_visitor/mod.rs index 7695128f255d4..4f8d5e0c2ade7 100644 --- a/src/frontend/src/optimizer/plan_visitor/mod.rs +++ b/src/frontend/src/optimizer/plan_visitor/mod.rs @@ -80,14 +80,15 @@ macro_rules! def_visitor { ($({ $convention:ident, $name:ident }),*) => { /// The visitor for plan nodes. visit all inputs and return the ret value of the left most input, /// and leaf node returns `R::default()` - pub trait PlanVisitor { - type DefaultBehavior: DefaultBehavior; + pub trait PlanVisitor { + type Result: Default; + type DefaultBehavior: DefaultBehavior; /// The behavior for the default implementations of `visit_xxx`. fn default_behavior() -> Self::DefaultBehavior; paste! { - fn visit(&mut self, plan: PlanRef) -> R{ + fn visit(&mut self, plan: PlanRef) -> Self::Result { match plan.node_type() { $( PlanNodeType::[<$convention $name>] => self.[](plan.downcast_ref::<[<$convention $name>]>().unwrap()), @@ -97,7 +98,7 @@ macro_rules! def_visitor { $( #[doc = "Visit [`" [<$convention $name>] "`] , the function should visit the inputs."] - fn [](&mut self, plan: &[<$convention $name>]) -> R { + fn [](&mut self, plan: &[<$convention $name>]) -> Self::Result { let results = plan.inputs().into_iter().map(|input| self.visit(input)); Self::default_behavior().apply(results) } @@ -121,17 +122,18 @@ macro_rules! impl_has_variant { pred: P, } - impl

PlanVisitor for HasWhere

+ impl

PlanVisitor for HasWhere

where P: FnMut(&$variant) -> bool, { - type DefaultBehavior = impl DefaultBehavior; + type Result = bool; + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a | b) } - fn [](&mut self, node: &$variant) -> bool { + fn [](&mut self, node: &$variant) -> Self::Result { (self.pred)(node) } } diff --git a/src/frontend/src/optimizer/plan_visitor/plan_correlated_id_finder.rs b/src/frontend/src/optimizer/plan_visitor/plan_correlated_id_finder.rs index e71497326a29a..7dd32e29b98bb 100644 --- a/src/frontend/src/optimizer/plan_visitor/plan_correlated_id_finder.rs +++ b/src/frontend/src/optimizer/plan_visitor/plan_correlated_id_finder.rs @@ -40,11 +40,13 @@ impl PlanCorrelatedIdFinder { } } -impl PlanVisitor<()> for PlanCorrelatedIdFinder { +impl PlanVisitor for PlanCorrelatedIdFinder { /// `correlated_input_ref` can only appear in `LogicalProject`, `LogicalFilter`, /// `LogicalJoin` or the `filter` clause of `PlanAggCall` of `LogicalAgg` now. - type DefaultBehavior = impl DefaultBehavior<()>; + type Result = (); + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { DefaultValue diff --git a/src/frontend/src/optimizer/plan_visitor/relation_collector_visitor.rs b/src/frontend/src/optimizer/plan_visitor/relation_collector_visitor.rs index 45fd2fdb90b14..a4b7102906c69 100644 --- a/src/frontend/src/optimizer/plan_visitor/relation_collector_visitor.rs +++ b/src/frontend/src/optimizer/plan_visitor/relation_collector_visitor.rs @@ -42,8 +42,10 @@ impl RelationCollectorVisitor { } } -impl PlanVisitor<()> for RelationCollectorVisitor { - type DefaultBehavior = impl DefaultBehavior<()>; +impl PlanVisitor for RelationCollectorVisitor { + type Result = (); + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { DefaultValue diff --git a/src/frontend/src/optimizer/plan_visitor/share_parent_counter.rs b/src/frontend/src/optimizer/plan_visitor/share_parent_counter.rs index 2b21f9d806e72..7d538392f9361 100644 --- a/src/frontend/src/optimizer/plan_visitor/share_parent_counter.rs +++ b/src/frontend/src/optimizer/plan_visitor/share_parent_counter.rs @@ -33,8 +33,10 @@ impl ShareParentCounter { } } -impl PlanVisitor<()> for ShareParentCounter { - type DefaultBehavior = impl DefaultBehavior<()>; +impl PlanVisitor for ShareParentCounter { + type Result = (); + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { DefaultValue diff --git a/src/frontend/src/optimizer/plan_visitor/side_effect_visitor.rs b/src/frontend/src/optimizer/plan_visitor/side_effect_visitor.rs index b7e87e656d58e..f36561d8d4457 100644 --- a/src/frontend/src/optimizer/plan_visitor/side_effect_visitor.rs +++ b/src/frontend/src/optimizer/plan_visitor/side_effect_visitor.rs @@ -19,8 +19,10 @@ use crate::optimizer::plan_node; /// eliminated trivially. pub struct SideEffectVisitor; -impl PlanVisitor for SideEffectVisitor { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for SideEffectVisitor { + type Result = bool; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a | b) diff --git a/src/frontend/src/optimizer/plan_visitor/sys_table_visitor.rs b/src/frontend/src/optimizer/plan_visitor/sys_table_visitor.rs index 7b5210ca68db7..35f4a7246e49a 100644 --- a/src/frontend/src/optimizer/plan_visitor/sys_table_visitor.rs +++ b/src/frontend/src/optimizer/plan_visitor/sys_table_visitor.rs @@ -27,8 +27,10 @@ impl SysTableVisitor { } } -impl PlanVisitor for SysTableVisitor { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for SysTableVisitor { + type Result = bool; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a | b) diff --git a/src/frontend/src/optimizer/plan_visitor/temporal_join_validator.rs b/src/frontend/src/optimizer/plan_visitor/temporal_join_validator.rs index 7fb0b1b49e309..d7da70b7a030b 100644 --- a/src/frontend/src/optimizer/plan_visitor/temporal_join_validator.rs +++ b/src/frontend/src/optimizer/plan_visitor/temporal_join_validator.rs @@ -29,8 +29,10 @@ impl TemporalJoinValidator { } } -impl PlanVisitor for TemporalJoinValidator { - type DefaultBehavior = impl DefaultBehavior; +impl PlanVisitor for TemporalJoinValidator { + type Result = bool; + + type DefaultBehavior = impl DefaultBehavior; fn default_behavior() -> Self::DefaultBehavior { Merge(|a, b| a | b)