Skip to main content

risingwave_frontend/optimizer/plan_node/generic/
mod.rs

1// Copyright 2022 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module contains the generic plan nodes that are shared by all the plan nodes.
16//! They are meant to reuse the common fields between logical, batch and stream nodes.
17
18use std::borrow::Cow;
19use std::hash::Hash;
20
21use pretty_xmlish::XmlNode;
22use risingwave_common::catalog::Schema;
23
24use super::{EqJoinPredicate, PlanNodeId};
25use crate::optimizer::optimizer_context::OptimizerContextRef;
26use crate::optimizer::property::{Distribution, FunctionalDependencySet};
27
28pub mod dynamic_filter;
29pub use dynamic_filter::*;
30mod hop_window;
31pub use hop_window::*;
32mod agg;
33pub use agg::*;
34mod project_set;
35pub use project_set::*;
36mod get_channel_delta_stats;
37pub use get_channel_delta_stats::*;
38mod table_function;
39pub use table_function::*;
40mod values;
41pub use values::*;
42mod join;
43pub use join::*;
44mod project;
45pub use project::*;
46mod filter;
47pub use filter::*;
48mod gap_fill;
49pub use gap_fill::*;
50mod match_recognize;
51pub use match_recognize::*;
52mod expand;
53pub use expand::*;
54mod source;
55pub use source::*;
56mod table_scan;
57pub use table_scan::*;
58mod sys_scan;
59pub use sys_scan::*;
60mod log_scan;
61pub use log_scan::*;
62
63mod cdc_scan;
64pub use cdc_scan::*;
65
66mod union;
67pub use union::*;
68mod top_n;
69pub use top_n::*;
70mod share;
71pub use share::*;
72mod dedup;
73pub use dedup::*;
74mod intersect;
75pub use intersect::*;
76mod over_window;
77pub use over_window::*;
78mod except;
79pub use except::*;
80mod update;
81pub use update::*;
82mod delete;
83pub use delete::*;
84mod insert;
85pub use insert::*;
86mod limit;
87pub use limit::*;
88mod max_one_row;
89pub use max_one_row::*;
90mod changelog;
91pub use changelog::*;
92mod now;
93pub use now::*;
94
95mod file_scan;
96pub use file_scan::*;
97
98mod iceberg_metadata_scan;
99pub use iceberg_metadata_scan::*;
100
101mod postgres_query;
102pub use postgres_query::*;
103
104mod mysql_query;
105
106pub use mysql_query::*;
107
108mod locality_provider;
109pub use locality_provider::*;
110
111mod vector_index_lookup_join;
112pub use vector_index_lookup_join::*;
113
114pub trait DistillUnit {
115    fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a>;
116}
117
118macro_rules! impl_distill_unit_from_fields {
119    ($name:ident, $bound:path) => {
120        use std::borrow::Cow;
121
122        use pretty_xmlish::XmlNode;
123        use $crate::optimizer::plan_node::generic::DistillUnit;
124        impl<PlanRef: $bound> DistillUnit for $name<PlanRef> {
125            fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a> {
126                XmlNode::simple_record(name, self.fields_pretty(), vec![])
127            }
128        }
129    };
130}
131pub(super) use impl_distill_unit_from_fields;
132
133#[auto_impl::auto_impl(&)]
134pub trait GenericPlanRef: Eq + Hash {
135    fn id(&self) -> PlanNodeId;
136    fn schema(&self) -> &Schema;
137    fn stream_key(&self) -> Option<&[usize]>;
138    fn functional_dependency(&self) -> &FunctionalDependencySet;
139    fn ctx(&self) -> OptimizerContextRef;
140}
141
142#[auto_impl::auto_impl(&)]
143pub trait PhysicalPlanRef: GenericPlanRef {
144    fn distribution(&self) -> &Distribution;
145}
146
147pub trait GenericPlanNode {
148    fn functional_dependency(&self) -> FunctionalDependencySet;
149    fn schema(&self) -> Schema;
150    fn stream_key(&self) -> Option<Vec<usize>>;
151    fn ctx(&self) -> OptimizerContextRef;
152}