Skip to main content

risingwave_stream/from_proto/
project.rs

1// Copyright 2022 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_expr::expr::build_non_strict_from_prost;
18use risingwave_pb::stream_plan::ProjectNode;
19
20use super::*;
21use crate::executor::project::ProjectExecutor;
22
23pub struct ProjectExecutorBuilder;
24
25impl_stream_node_body!(Project(ProjectNode) => ProjectExecutorBuilder);
26
27impl ExecutorBuilder for ProjectExecutorBuilder {
28    type Node = ProjectNode;
29
30    async fn new_boxed_executor(
31        params: ExecutorParams,
32        node: &Self::Node,
33        _store: impl StateStore,
34    ) -> StreamResult<Executor> {
35        let [input]: [_; 1] = params.input.try_into().unwrap();
36        let project_exprs: Vec<_> = node
37            .get_select_list()
38            .iter()
39            .map(|e| build_non_strict_from_prost(e, params.eval_error_report.clone()))
40            .try_collect()?;
41
42        let watermark_derivations = MultiMap::from_iter(
43            node.get_watermark_input_cols()
44                .iter()
45                .map(|idx| *idx as usize)
46                .zip_eq_fast(
47                    node.get_watermark_output_cols()
48                        .iter()
49                        .map(|idx| *idx as usize),
50                ),
51        );
52        let nondecreasing_expr_indices = node
53            .get_nondecreasing_exprs()
54            .iter()
55            .map(|idx| *idx as usize)
56            .collect();
57        let exec = ProjectExecutor::new(
58            params.actor_context,
59            input,
60            project_exprs,
61            watermark_derivations,
62            nondecreasing_expr_indices,
63            node.noop_update_hint,
64        );
65        Ok((params.info, exec).into())
66    }
67}