risingwave_frontend/optimizer/plan_node/
batch_table_function.rs1use risingwave_pb::batch_plan::TableFunctionNode;
16use risingwave_pb::batch_plan::plan_node::NodeBody;
17
18use super::batch::prelude::*;
19use super::utils::impl_distill_by_unit;
20use super::{
21 BatchPlanRef as PlanRef, ExprRewritable, PlanBase, PlanTreeNodeLeaf, ToBatchPb,
22 ToDistributedBatch, generic,
23};
24use crate::error::Result;
25use crate::expr::{ExprRewriter, ExprVisitor};
26use crate::optimizer::plan_node::ToLocalBatch;
27use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
28use crate::optimizer::property::{Distribution, Order};
29
30#[derive(Debug, Clone, PartialEq, Eq, Hash)]
31pub struct BatchTableFunction {
32 pub base: PlanBase<Batch>,
33 core: generic::TableFunction,
34}
35
36impl PlanTreeNodeLeaf for BatchTableFunction {}
37impl_plan_tree_node_for_leaf! { Batch, BatchTableFunction }
38
39impl BatchTableFunction {
40 pub fn new(core: generic::TableFunction) -> Self {
41 Self::with_dist(core, Distribution::Single)
42 }
43
44 pub fn with_dist(core: generic::TableFunction, dist: Distribution) -> Self {
45 let base = PlanBase::new_batch_with_core(&core, dist, Order::any());
46 BatchTableFunction { base, core }
47 }
48}
49
50impl_distill_by_unit!(BatchTableFunction, core, "BatchTableFunction");
51
52impl ToDistributedBatch for BatchTableFunction {
53 fn to_distributed(&self) -> Result<PlanRef> {
54 Ok(Self::with_dist(self.core.clone(), Distribution::Single).into())
55 }
56}
57
58impl ToBatchPb for BatchTableFunction {
59 fn to_batch_prost_body(&self) -> NodeBody {
60 NodeBody::TableFunction(TableFunctionNode {
61 table_function: Some(self.core.table_function.to_protobuf()),
62 })
63 }
64}
65
66impl ToLocalBatch for BatchTableFunction {
67 fn to_local(&self) -> Result<PlanRef> {
68 Ok(Self::with_dist(self.core.clone(), Distribution::Single).into())
69 }
70}
71
72impl ExprRewritable<Batch> for BatchTableFunction {
73 fn has_rewritable_expr(&self) -> bool {
74 true
75 }
76
77 fn rewrite_exprs(&self, r: &mut dyn ExprRewriter) -> PlanRef {
78 let mut core = self.core.clone();
79 core.rewrite_exprs(r);
80 Self::new(core).into()
81 }
82}
83
84impl ExprVisitable for BatchTableFunction {
85 fn visit_exprs(&self, v: &mut dyn ExprVisitor) {
86 self.core.visit_exprs(v);
87 }
88}