risingwave_stream/from_proto/
project_set.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 multimap::MultiMap;
16use risingwave_common::util::iter_util::ZipEqFast;
17use risingwave_pb::stream_plan::ProjectSetNode;
18
19use super::*;
20use crate::executor::project::{ProjectSetExecutor, ProjectSetSelectItem};
21
22pub struct ProjectSetExecutorBuilder;
23
24impl ExecutorBuilder for ProjectSetExecutorBuilder {
25    type Node = ProjectSetNode;
26
27    async fn new_boxed_executor(
28        params: ExecutorParams,
29        node: &Self::Node,
30        _store: impl StateStore,
31    ) -> StreamResult<Executor> {
32        let chunk_size = params.config.developer.chunk_size;
33
34        let [input]: [_; 1] = params.input.try_into().unwrap();
35        let select_list: Vec<_> = node
36            .get_select_list()
37            .iter()
38            .map(|proto| {
39                ProjectSetSelectItem::from_prost(
40                    proto,
41                    params.eval_error_report.clone(),
42                    chunk_size,
43                )
44            })
45            .try_collect()?;
46        let watermark_derivations = MultiMap::from_iter(
47            node.get_watermark_input_cols()
48                .iter()
49                .map(|idx| *idx as usize)
50                .zip_eq_fast(
51                    node.get_watermark_expr_indices()
52                        .iter()
53                        .map(|idx| *idx as usize),
54                ),
55        );
56        let nondecreasing_expr_indices = node
57            .get_nondecreasing_exprs()
58            .iter()
59            .map(|idx| *idx as usize)
60            .collect();
61
62        let exec = ProjectSetExecutor::new(
63            params.actor_context,
64            input,
65            select_list,
66            chunk_size,
67            watermark_derivations,
68            nondecreasing_expr_indices,
69            params.eval_error_report,
70        );
71        Ok((params.info, exec).into())
72    }
73}