risingwave_frontend/optimizer/plan_node/generic/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2024 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This module contains the generic plan nodes that are shared by all the plan nodes.
//! They are meant to reuse the common fields between logical, batch and stream nodes.

use std::borrow::Cow;
use std::hash::Hash;

use pretty_xmlish::XmlNode;
use risingwave_common::catalog::Schema;

use super::{stream, EqJoinPredicate, PlanNodeId};
use crate::optimizer::optimizer_context::OptimizerContextRef;
use crate::optimizer::property::{Distribution, FunctionalDependencySet};

pub mod dynamic_filter;
pub use dynamic_filter::*;
mod hop_window;
pub use hop_window::*;
mod agg;
pub use agg::*;
mod project_set;
pub use project_set::*;
mod join;
pub use join::*;
mod project;
pub use project::*;
mod filter;
pub use filter::*;
mod expand;
pub use expand::*;
mod source;
pub use source::*;
mod table_scan;
pub use table_scan::*;
mod sys_scan;
pub use sys_scan::*;
mod log_scan;
pub use log_scan::*;

mod cdc_scan;
pub use cdc_scan::*;

mod union;
pub use union::*;
mod top_n;
pub use top_n::*;
mod share;
pub use share::*;
mod dedup;
pub use dedup::*;
mod intersect;
pub use intersect::*;
mod over_window;
pub use over_window::*;
mod except;
pub use except::*;
mod update;
pub use update::*;
mod delete;
pub use delete::*;
mod insert;
pub use insert::*;
mod limit;
pub use limit::*;
mod max_one_row;
pub use max_one_row::*;
mod cte_ref;
pub use cte_ref::*;
mod recursive_union;
pub use recursive_union::*;
mod changelog;
pub use changelog::*;
mod now;
pub use now::*;

mod file_scan;
pub use file_scan::*;

mod postgres_query;
pub use postgres_query::*;

mod mysql_query;
pub use mysql_query::*;

pub trait DistillUnit {
    fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a>;
}

macro_rules! impl_distill_unit_from_fields {
    ($name:ident, $bound:path) => {
        use std::borrow::Cow;

        use pretty_xmlish::XmlNode;
        use $crate::optimizer::plan_node::generic::DistillUnit;
        impl<PlanRef: $bound> DistillUnit for $name<PlanRef> {
            fn distill_with_name<'a>(&self, name: impl Into<Cow<'a, str>>) -> XmlNode<'a> {
                XmlNode::simple_record(name, self.fields_pretty(), vec![])
            }
        }
    };
}
pub(super) use impl_distill_unit_from_fields;

#[auto_impl::auto_impl(&)]
pub trait GenericPlanRef: Eq + Hash {
    fn id(&self) -> PlanNodeId;
    fn schema(&self) -> &Schema;
    fn stream_key(&self) -> Option<&[usize]>;
    fn functional_dependency(&self) -> &FunctionalDependencySet;
    fn ctx(&self) -> OptimizerContextRef;
}

#[auto_impl::auto_impl(&)]
pub trait PhysicalPlanRef: GenericPlanRef {
    fn distribution(&self) -> &Distribution;
}

pub trait GenericPlanNode {
    fn functional_dependency(&self) -> FunctionalDependencySet;
    fn schema(&self) -> Schema;
    fn stream_key(&self) -> Option<Vec<usize>>;
    fn ctx(&self) -> OptimizerContextRef;
}