Skip to content

Commit

Permalink
feat(optimizer): support expr visitable for plan node (#13587)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 authored Nov 23, 2023
1 parent b3eecb3 commit b3866b7
Show file tree
Hide file tree
Showing 96 changed files with 600 additions and 51 deletions.
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::generic::PhysicalPlanRef;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, Order, RequiredDist};
Expand Down Expand Up @@ -83,3 +84,5 @@ impl ToLocalBatch for BatchDelete {
}

impl ExprRewritable for BatchDelete {}

impl ExprVisitable for BatchDelete {}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use risingwave_pb::batch_plan::{ExchangeNode, MergeSortExchangeNode};
use super::batch::prelude::*;
use super::utils::{childless_record, Distill};
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, DistributionDisplay, Order, OrderDisplay};

Expand Down Expand Up @@ -100,3 +101,5 @@ impl ToLocalBatch for BatchExchange {
}

impl ExprRewritable for BatchExchange {}

impl ExprVisitable for BatchExchange {}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use risingwave_pb::batch_plan::ExpandNode;
use super::batch::prelude::*;
use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::{
PlanBase, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch, ToLocalBatch,
};
Expand Down Expand Up @@ -99,3 +100,5 @@ impl ToLocalBatch for BatchExpand {
}

impl ExprRewritable for BatchExpand {}

impl ExprVisitable for BatchExpand {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use risingwave_pb::batch_plan::FilterNode;
use super::batch::prelude::*;
use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::{Expr, ExprImpl, ExprRewriter};
use crate::expr::{Expr, ExprImpl, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::{PlanBase, ToLocalBatch};
use crate::utils::Condition;

Expand Down Expand Up @@ -94,3 +95,9 @@ impl ExprRewritable for BatchFilter {
Self::new(core).into()
}
}

impl ExprVisitable for BatchFilter {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v)
}
}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_group_topn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Order, RequiredDist};

Expand Down Expand Up @@ -91,3 +92,5 @@ impl ToLocalBatch for BatchGroupTopN {
}

impl ExprRewritable for BatchGroupTopN {}

impl ExprVisitable for BatchGroupTopN {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_hash_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use super::{
ExprRewritable, PlanBase, PlanNodeType, PlanRef, PlanTreeNodeUnary, ToBatchPb,
ToDistributedBatch,
};
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, Order, RequiredDist};
use crate::utils::{ColIndexMappingRewriteExt, IndexSet};
Expand Down Expand Up @@ -166,3 +167,9 @@ impl ExprRewritable for BatchHashAgg {
Self::new(core).into()
}
}

impl ExprVisitable for BatchHashAgg {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use super::{
EqJoinPredicate, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeBinary, ToBatchPb,
ToDistributedBatch,
};
use crate::expr::{Expr, ExprRewriter};
use crate::expr::{Expr, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::utils::IndicesDisplay;
use crate::optimizer::plan_node::{EqJoinPredicateDisplay, ToLocalBatch};
use crate::optimizer::property::{Distribution, Order, RequiredDist};
Expand Down Expand Up @@ -239,3 +240,9 @@ impl ExprRewritable for BatchHashJoin {
Self::new(core, self.eq_join_predicate.rewrite_exprs(r)).into()
}
}

impl ExprVisitable for BatchHashJoin {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
10 changes: 9 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_hop_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
use crate::expr::{Expr, ExprImpl, ExprRewriter};
use crate::expr::{Expr, ExprImpl, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Order, RequiredDist};
use crate::utils::ColIndexMappingRewriteExt;
Expand Down Expand Up @@ -160,3 +161,10 @@ impl ExprRewritable for BatchHopWindow {
.into()
}
}

impl ExprVisitable for BatchHopWindow {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.window_start_exprs.iter().for_each(|e| v.visit_expr(e));
self.window_end_exprs.iter().for_each(|e| v.visit_expr(e));
}
}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use super::generic::GenericPlanRef;
use super::utils::{childless_record, Distill};
use super::{generic, ExprRewritable, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::Expr;
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::{PlanBase, ToLocalBatch};
use crate::optimizer::property::{Distribution, Order, RequiredDist};

Expand Down Expand Up @@ -113,3 +114,5 @@ impl ToLocalBatch for BatchInsert {
}

impl ExprRewritable for BatchInsert {}

impl ExprVisitable for BatchInsert {}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Order, RequiredDist};

Expand Down Expand Up @@ -106,3 +107,5 @@ impl ToLocalBatch for BatchLimit {
}

impl ExprRewritable for BatchLimit {}

impl ExprVisitable for BatchLimit {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_lookup_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use super::batch::prelude::*;
use super::generic::{self, GenericPlanRef};
use super::utils::{childless_record, Distill};
use super::ExprRewritable;
use crate::expr::{Expr, ExprRewriter};
use crate::expr::{Expr, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::utils::IndicesDisplay;
use crate::optimizer::plan_node::{
EqJoinPredicate, EqJoinPredicateDisplay, LogicalScan, PlanBase, PlanTreeNodeUnary, ToBatchPb,
Expand Down Expand Up @@ -294,3 +295,9 @@ impl ExprRewritable for BatchLookupJoin {
.into()
}
}

impl ExprVisitable for BatchLookupJoin {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use super::batch::prelude::*;
use super::generic::{self, GenericPlanRef};
use super::utils::{childless_record, Distill};
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeBinary, ToBatchPb, ToDistributedBatch};
use crate::expr::{Expr, ExprImpl, ExprRewriter};
use crate::expr::{Expr, ExprImpl, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::utils::IndicesDisplay;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, Order, RequiredDist};
Expand Down Expand Up @@ -139,3 +140,9 @@ impl ExprRewritable for BatchNestedLoopJoin {
Self::new(core).into()
}
}

impl ExprVisitable for BatchNestedLoopJoin {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_over_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
ToLocalBatch,
};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::property::{Order, RequiredDist};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -125,3 +126,5 @@ impl ToBatchPb for BatchOverWindow {
}

impl ExprRewritable for BatchOverWindow {}

impl ExprVisitable for BatchOverWindow {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use super::utils::{childless_record, Distill};
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
use crate::expr::{Expr, ExprImpl, ExprRewriter};
use crate::expr::{Expr, ExprImpl, ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::utils::ColIndexMappingRewriteExt;

Expand Down Expand Up @@ -114,3 +115,9 @@ impl ExprRewritable for BatchProject {
Self::new(core).into()
}
}

impl ExprVisitable for BatchProject {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_project_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use risingwave_pb::batch_plan::ProjectSetNode;
use super::batch::prelude::*;
use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable};
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::{
PlanBase, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch, ToLocalBatch,
};
Expand Down Expand Up @@ -101,3 +102,9 @@ impl ExprRewritable for BatchProjectSet {
Self::new(core).into()
}
}

impl ExprVisitable for BatchProjectSet {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_seq_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use super::batch::prelude::*;
use super::utils::{childless_record, Distill};
use super::{generic, ExprRewritable, PlanBase, PlanRef, ToBatchPb, ToDistributedBatch};
use crate::catalog::ColumnId;
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, DistributionDisplay, Order};

Expand Down Expand Up @@ -255,3 +256,9 @@ impl ExprRewritable for BatchSeqScan {
Self::new(core, self.scan_ranges.clone()).into()
}
}

impl ExprVisitable for BatchSeqScan {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_simple_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use super::batch::prelude::*;
use super::generic::{self, GenericPlanRef, PlanAggCall};
use super::utils::impl_distill_by_unit;
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::{BatchExchange, ToLocalBatch};
use crate::optimizer::property::{Distribution, Order, RequiredDist};

Expand Down Expand Up @@ -143,3 +144,9 @@ impl ExprRewritable for BatchSimpleAgg {
Self::new(core).into()
}
}

impl ExprVisitable for BatchSimpleAgg {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
3 changes: 3 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::batch::prelude::*;
use super::batch::BatchPlanRef;
use super::utils::{childless_record, Distill};
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Order, OrderDisplay};

Expand Down Expand Up @@ -85,3 +86,5 @@ impl ToLocalBatch for BatchSort {
}

impl ExprRewritable for BatchSort {}

impl ExprVisitable for BatchSort {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_sort_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use super::batch::prelude::*;
use super::generic::{self, GenericPlanRef, PlanAggCall};
use super::utils::impl_distill_by_unit;
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::{Expr, ExprImpl, ExprRewriter, InputRef};
use crate::expr::{Expr, ExprImpl, ExprRewriter, ExprVisitor, InputRef};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Order, RequiredDist};
use crate::utils::{ColIndexMappingRewriteExt, IndexSet};
Expand Down Expand Up @@ -140,3 +141,9 @@ impl ExprRewritable for BatchSortAgg {
Self::new(new_logical).into()
}
}

impl ExprVisitable for BatchSortAgg {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
4 changes: 4 additions & 0 deletions src/frontend/src/optimizer/plan_node/batch_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::{
generic, ExprRewritable, PlanBase, PlanRef, ToBatchPb, ToDistributedBatch, ToLocalBatch,
};
use crate::catalog::source_catalog::SourceCatalog;
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::property::{Distribution, Order};

/// [`BatchSource`] represents a table/connector source at the very beginning of the graph.
Expand Down Expand Up @@ -112,4 +113,7 @@ impl ToBatchPb for BatchSource {
})
}
}

impl ExprRewritable for BatchSource {}

impl ExprVisitable for BatchSource {}
9 changes: 8 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_sys_seq_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use risingwave_pb::plan_common::PbColumnDesc;
use super::batch::prelude::*;
use super::utils::{childless_record, Distill};
use super::{generic, ExprRewritable, PlanBase, PlanRef, ToBatchPb, ToDistributedBatch};
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, DistributionDisplay, Order};

Expand Down Expand Up @@ -222,3 +223,9 @@ impl ExprRewritable for BatchSysSeqScan {
Self::new(core, self.scan_ranges.clone()).into()
}
}

impl ExprVisitable for BatchSysSeqScan {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.core.visit_exprs(v);
}
}
13 changes: 12 additions & 1 deletion src/frontend/src/optimizer/plan_node/batch_table_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use risingwave_pb::batch_plan::TableFunctionNode;
use super::batch::prelude::*;
use super::utils::{childless_record, Distill};
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeLeaf, ToBatchPb, ToDistributedBatch};
use crate::expr::ExprRewriter;
use crate::expr::{ExprRewriter, ExprVisitor};
use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
use crate::optimizer::plan_node::logical_table_function::LogicalTableFunction;
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, Order};
Expand Down Expand Up @@ -94,3 +95,13 @@ impl ExprRewritable for BatchTableFunction {
.into()
}
}

impl ExprVisitable for BatchTableFunction {
fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
self.logical
.table_function
.args
.iter()
.for_each(|e| v.visit_expr(e));
}
}
Loading

0 comments on commit b3866b7

Please sign in to comment.