Skip to main content

risingwave_frontend/optimizer/plan_node/generic/
get_channel_delta_stats.rs

1// Copyright 2026 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 educe::Educe;
16use pretty_xmlish::{Pretty, Str, XmlNode};
17use risingwave_common::catalog::Schema;
18
19use super::{DistillUnit, GenericPlanNode};
20use crate::optimizer::optimizer_context::OptimizerContextRef;
21use crate::optimizer::plan_node::utils::childless_record;
22use crate::optimizer::property::FunctionalDependencySet;
23
24/// The convention-independent core of a plan node that retrieves channel delta statistics.
25#[derive(Debug, Clone, Educe)]
26#[educe(PartialEq, Eq, Hash)]
27pub struct GetChannelDeltaStats {
28    pub schema: Schema,
29    pub at_time: Option<u64>,
30    pub time_offset: Option<u64>,
31
32    #[educe(PartialEq(ignore))]
33    #[educe(Hash(ignore))]
34    pub ctx: OptimizerContextRef,
35}
36
37impl GetChannelDeltaStats {
38    pub fn new(
39        ctx: OptimizerContextRef,
40        schema: Schema,
41        at_time: Option<u64>,
42        time_offset: Option<u64>,
43    ) -> Self {
44        Self {
45            schema,
46            at_time,
47            time_offset,
48            ctx,
49        }
50    }
51}
52
53impl GenericPlanNode for GetChannelDeltaStats {
54    fn schema(&self) -> Schema {
55        self.schema.clone()
56    }
57
58    fn stream_key(&self) -> Option<Vec<usize>> {
59        None
60    }
61
62    fn ctx(&self) -> OptimizerContextRef {
63        self.ctx.clone()
64    }
65
66    fn functional_dependency(&self) -> FunctionalDependencySet {
67        FunctionalDependencySet::new(self.schema.len())
68    }
69}
70
71impl DistillUnit for GetChannelDeltaStats {
72    fn distill_with_name<'a>(&self, name: impl Into<Str<'a>>) -> XmlNode<'a> {
73        childless_record(
74            name,
75            vec![
76                ("at_time", Pretty::debug(&self.at_time)),
77                ("time_offset", Pretty::debug(&self.time_offset)),
78            ],
79        )
80    }
81}