Skip to main content

risingwave_frontend/optimizer/plan_node/
logical_get_channel_delta_stats.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::bail_not_implemented;
16use risingwave_common::catalog::Schema;
17
18use super::utils::impl_distill_by_unit;
19use super::{
20    ColPrunable, ExprRewritable, Logical, LogicalFilter, LogicalPlanRef as PlanRef, PlanBase,
21    PredicatePushdown, ToBatch, ToStream, generic,
22};
23use crate::error::Result;
24use crate::optimizer::plan_node::{
25    ColumnPruningContext, LogicalProject, PredicatePushdownContext, RewriteStreamContext,
26    ToStreamContext,
27};
28use crate::utils::{ColIndexMapping, Condition};
29
30/// `LogicalGetChannelDeltaStats` represents a plan node that retrieves channel statistics
31/// from the dashboard API. It has no inputs and returns channel stats data.
32#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33pub struct LogicalGetChannelDeltaStats {
34    pub base: PlanBase<Logical>,
35    core: generic::GetChannelDeltaStats,
36}
37
38impl LogicalGetChannelDeltaStats {
39    /// Create a new `LogicalGetChannelDeltaStats` node
40    pub fn new(
41        ctx: crate::OptimizerContextRef,
42        schema: Schema,
43        at_time: Option<u64>,
44        time_offset: Option<u64>,
45    ) -> Self {
46        let core = generic::GetChannelDeltaStats::new(ctx, schema, at_time, time_offset);
47        let base = PlanBase::new_logical_with_core(&core);
48        Self { base, core }
49    }
50
51    /// Get the `at_time` parameter
52    pub fn at_time(&self) -> Option<u64> {
53        self.core.at_time
54    }
55
56    /// Get the `time_offset` parameter
57    pub fn time_offset(&self) -> Option<u64> {
58        self.core.time_offset
59    }
60}
61
62impl_plan_tree_node_for_leaf! { Logical, LogicalGetChannelDeltaStats }
63impl_distill_by_unit!(
64    LogicalGetChannelDeltaStats,
65    core,
66    "LogicalGetChannelDeltaStats"
67);
68
69impl ExprRewritable<Logical> for LogicalGetChannelDeltaStats {}
70
71impl crate::optimizer::plan_node::expr_visitable::ExprVisitable for LogicalGetChannelDeltaStats {}
72
73impl ColPrunable for LogicalGetChannelDeltaStats {
74    fn prune_col(&self, required_cols: &[usize], _ctx: &mut ColumnPruningContext) -> PlanRef {
75        LogicalProject::with_out_col_idx(self.clone().into(), required_cols.iter().cloned()).into()
76    }
77}
78
79impl PredicatePushdown for LogicalGetChannelDeltaStats {
80    fn predicate_pushdown(
81        &self,
82        predicate: Condition,
83        _ctx: &mut PredicatePushdownContext,
84    ) -> PlanRef {
85        LogicalFilter::create(self.clone().into(), predicate)
86    }
87}
88
89impl ToBatch for LogicalGetChannelDeltaStats {
90    fn to_batch(&self) -> Result<crate::optimizer::plan_node::BatchPlanRef> {
91        use crate::optimizer::plan_node::BatchGetChannelDeltaStats;
92        Ok(BatchGetChannelDeltaStats::new(self.core.clone()).into())
93    }
94}
95
96impl ToStream for LogicalGetChannelDeltaStats {
97    fn to_stream(
98        &self,
99        _ctx: &mut ToStreamContext,
100    ) -> Result<crate::optimizer::plan_node::StreamPlanRef> {
101        bail_not_implemented!("Streaming not implemented for LogicalGetChannelDeltaStats")
102    }
103
104    fn logical_rewrite_for_stream(
105        &self,
106        _ctx: &mut RewriteStreamContext,
107    ) -> Result<(PlanRef, ColIndexMapping)> {
108        bail_not_implemented!("Streaming not implemented for LogicalGetChannelDeltaStats")
109    }
110}