risingwave_frontend/planner/
mod.rs1use std::collections::HashMap;
16
17use crate::binder::{BoundStatement, ShareId};
18use crate::error::Result;
19use crate::optimizer::{LogicalPlanRoot, OptimizerContextRef};
20
21mod changelog;
22mod delete;
23mod insert;
24mod query;
25mod relation;
26mod select;
27mod set_expr;
28mod set_operation;
29mod statement;
30mod update;
31mod values;
32pub use query::LIMIT_ALL_COUNT;
33
34use crate::optimizer::plan_node::LogicalPlanRef as PlanRef;
35
36pub struct Planner {
38 ctx: OptimizerContextRef,
39 share_cache: HashMap<ShareId, PlanRef>,
42 plan_for: PlanFor,
44}
45
46#[derive(Debug, Copy, Clone)]
47pub enum PlanFor {
48 Stream,
49 StreamIcebergEngineInternal,
52 Batch,
54 BatchDql,
60}
61
62impl Planner {
63 pub fn new_for_batch_dql(ctx: OptimizerContextRef) -> Planner {
64 Planner {
65 ctx,
66 share_cache: Default::default(),
67 plan_for: PlanFor::BatchDql,
68 }
69 }
70
71 pub fn new_for_batch(ctx: OptimizerContextRef) -> Planner {
72 Planner {
73 ctx,
74 share_cache: Default::default(),
75 plan_for: PlanFor::Batch,
76 }
77 }
78
79 pub fn new_for_stream(ctx: OptimizerContextRef) -> Planner {
80 Planner {
81 ctx,
82 share_cache: Default::default(),
83 plan_for: PlanFor::Stream,
84 }
85 }
86
87 pub fn new_for_iceberg_table_engine_sink(ctx: OptimizerContextRef) -> Planner {
88 Planner {
89 ctx,
90 share_cache: Default::default(),
91 plan_for: PlanFor::StreamIcebergEngineInternal,
92 }
93 }
94
95 pub fn plan(&mut self, stmt: BoundStatement) -> Result<LogicalPlanRoot> {
97 self.plan_statement(stmt)
98 }
99
100 pub fn ctx(&self) -> OptimizerContextRef {
101 self.ctx.clone()
102 }
103
104 pub fn plan_for(&self) -> PlanFor {
105 self.plan_for
106 }
107}