risingwave_frontend/optimizer/plan_visitor/
rw_timestamp_validator.rs

1// Copyright 2025 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
15use risingwave_common::catalog::{RW_TIMESTAMP_COLUMN_ID, RW_TIMESTAMP_COLUMN_NAME};
16
17use super::{DefaultBehavior, Merge, StreamPlanVisitor};
18use crate::optimizer::plan_node::{StreamPlanRef as PlanRef, StreamTableScan};
19use crate::optimizer::plan_visitor::PlanVisitor;
20
21#[derive(Debug, Clone, Default)]
22pub struct RwTimestampValidator {}
23
24impl RwTimestampValidator {
25    pub fn select_rw_timestamp_in_stream_query(plan: PlanRef) -> bool {
26        RwTimestampValidator::default().visit(plan)
27    }
28}
29
30impl StreamPlanVisitor for RwTimestampValidator {
31    type Result = bool;
32
33    type DefaultBehavior = impl DefaultBehavior<Self::Result>;
34
35    fn default_behavior() -> Self::DefaultBehavior {
36        Merge(|a, b| a | b)
37    }
38
39    fn visit_stream_table_scan(&mut self, stream_table_scan: &StreamTableScan) -> bool {
40        stream_table_scan
41            .core()
42            .column_descs()
43            .iter()
44            .any(|c| c.column_id == RW_TIMESTAMP_COLUMN_ID && c.name == RW_TIMESTAMP_COLUMN_NAME)
45    }
46}