Skip to main content

risingwave_stream/from_proto/
eowc_gap_fill.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 std::collections::HashMap;
16use std::sync::Arc;
17
18use itertools::Itertools;
19use risingwave_common::gap_fill::FillStrategy;
20use risingwave_expr::expr::build_non_strict_from_prost;
21use risingwave_pb::stream_plan::EowcGapFillNode;
22use risingwave_storage::StateStore;
23
24use super::ExecutorBuilder;
25use crate::common::table::state_table::StateTableBuilder;
26use crate::error::StreamResult;
27use crate::executor::Executor;
28use crate::executor::eowc::{EowcGapFillExecutor, EowcGapFillExecutorArgs};
29use crate::task::ExecutorParams;
30
31pub struct EowcGapFillExecutorBuilder;
32
33impl_stream_node_body!(EowcGapFill(EowcGapFillNode) => EowcGapFillExecutorBuilder);
34
35impl ExecutorBuilder for EowcGapFillExecutorBuilder {
36    type Node = EowcGapFillNode;
37
38    async fn new_boxed_executor(
39        params: ExecutorParams,
40        node: &EowcGapFillNode,
41        store: impl StateStore,
42    ) -> StreamResult<Executor> {
43        let [input]: [_; 1] = params.input.try_into().unwrap();
44
45        let time_column_index = node.get_time_column_index() as usize;
46
47        // Parse interval from ExprNode
48        let interval_expr_node = node.get_interval()?;
49        let gap_interval =
50            build_non_strict_from_prost(interval_expr_node, params.eval_error_report.clone())?;
51
52        let fill_columns: Vec<usize> = node
53            .get_fill_columns()
54            .iter()
55            .map(|&x| x as usize)
56            .collect();
57
58        let fill_strategies: Vec<FillStrategy> = node
59            .get_fill_strategies()
60            .iter()
61            .map(|s| match s.as_str() {
62                "locf" => Ok(FillStrategy::Locf),
63                "interpolate" => Ok(FillStrategy::Interpolate),
64                "null" => Ok(FillStrategy::Null),
65                _ => anyhow::bail!("unknown fill strategy: {}", s),
66            })
67            .collect::<anyhow::Result<_>>()?;
68
69        let fill_columns_with_strategies: HashMap<usize, FillStrategy> =
70            fill_columns.into_iter().zip_eq(fill_strategies).collect();
71
72        let vnodes = params.vnode_bitmap.map(Arc::new);
73
74        let prev_row_table =
75            StateTableBuilder::new(node.get_prev_row_table().as_ref().unwrap(), store, vnodes)
76                .forbid_preload_all_rows()
77                .build()
78                .await;
79
80        let partition_by_indices: Vec<usize> = node
81            .get_partition_by_indices()
82            .iter()
83            .map(|&x| x as usize)
84            .collect();
85
86        let exec = EowcGapFillExecutor::new(EowcGapFillExecutorArgs {
87            actor_ctx: params.actor_context,
88            input,
89            schema: params.info.schema.clone(),
90            prev_row_table,
91            chunk_size: params.config.developer.chunk_size,
92            time_column_index,
93            fill_columns: fill_columns_with_strategies,
94            gap_interval,
95            high_gap_fill_amplification_threshold: params
96                .config
97                .developer
98                .high_gap_fill_amplification_threshold,
99            partition_by_indices,
100        });
101
102        Ok((params.info, exec).into())
103    }
104}