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 expand;
51pub use expand::*;
52mod source;
53pub use source::*;
54mod table_scan;
55pub use table_scan::*;
56mod sys_scan;
57pub use sys_scan::*;
58mod log_scan;
59pub use log_scan::*;
60
61mod cdc_scan;
62pub use cdc_scan::*;
63
64mod union;
65pub use union::*;
66mod top_n;
67pub use top_n::*;
68mod share;
69pub use share::*;
70mod dedup;
71pub use dedup::*;
72mod intersect;
73pub use intersect::*;
74mod over_window;
75pub use over_window::*;
76mod except;
77pub use except::*;
78mod update;
79pub use update::*;
80mod delete;
81pub use delete::*;
82mod insert;
83pub use insert::*;
84mod limit;
85pub use limit::*;
86mod max_one_row;
87pub use max_one_row::*;
88mod changelog;
89pub use changelog::*;
90mod now;
91pub use now::*;
92
93mod file_scan;
94pub use file_scan::*;
95
96mod iceberg_metadata_scan;
97pub use iceberg_metadata_scan::*;
98
99mod postgres_query;
100pub use postgres_query::*;
101
102mod mysql_query;
103
104pub use mysql_query::*;
105
106mod locality_provider;
107pub use locality_provider::*;
108
109mod vector_index_lookup_join;
110pub use vector_index_lookup_join::*;
111
112pub trait DistillUnit {
113    fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a>;
114}
115
116macro_rules! impl_distill_unit_from_fields {
117    ($name:ident, $bound:path) => {
118        use std::borrow::Cow;
119
120        use pretty_xmlish::XmlNode;
121        use $crate::optimizer::plan_node::generic::DistillUnit;
122        impl<PlanRef: $bound> DistillUnit for $name<PlanRef> {
123            fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a> {
124                XmlNode::simple_record(name, self.fields_pretty(), vec![])
125            }
126        }
127    };
128}
129pub(super) use impl_distill_unit_from_fields;
130
131#[auto_impl::auto_impl(&)]
132pub trait GenericPlanRef: Eq + Hash {
133    fn id(&self) -> PlanNodeId;
134    fn schema(&self) -> &Schema;
135    fn stream_key(&self) -> Option<&[usize]>;
136    fn functional_dependency(&self) -> &FunctionalDependencySet;
137    fn ctx(&self) -> OptimizerContextRef;
138}
139
140#[auto_impl::auto_impl(&)]
141pub trait PhysicalPlanRef: GenericPlanRef {
142    fn distribution(&self) -> &Distribution;
143}
144
145pub trait GenericPlanNode {
146    fn functional_dependency(&self) -> FunctionalDependencySet;
147    fn schema(&self) -> Schema;
148    fn stream_key(&self) -> Option<Vec<usize>>;
149    fn ctx(&self) -> OptimizerContextRef;
150}