Skip to main content

risingwave_stream/from_proto/
hop_window.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 risingwave_expr::expr::build_non_strict_from_prost;
16use risingwave_pb::stream_plan::HopWindowNode;
17
18use super::*;
19use crate::executor::HopWindowExecutor;
20
21pub struct HopWindowExecutorBuilder;
22
23impl_stream_node_body!(HopWindow(HopWindowNode) => HopWindowExecutorBuilder);
24
25impl ExecutorBuilder for HopWindowExecutorBuilder {
26    type Node = HopWindowNode;
27
28    async fn new_boxed_executor(
29        params: ExecutorParams,
30        node: &Self::Node,
31        _store: impl StateStore,
32    ) -> StreamResult<Executor> {
33        let input = params.input.into_iter().next().unwrap();
34        // TODO: reuse the schema derivation with frontend.
35        let output_indices = node
36            .get_output_indices()
37            .iter()
38            .map(|&x| x as usize)
39            .collect_vec();
40
41        let window_start_exprs: Vec<_> = node
42            .get_window_start_exprs()
43            .iter()
44            .map(|e| build_non_strict_from_prost(e, params.eval_error_report.clone()))
45            .try_collect()?;
46        let window_end_exprs: Vec<_> = node
47            .get_window_end_exprs()
48            .iter()
49            .map(|e| build_non_strict_from_prost(e, params.eval_error_report.clone()))
50            .try_collect()?;
51
52        let time_col = node.get_time_col() as usize;
53        let window_slide = node.get_window_slide()?.into();
54        let window_size = node.get_window_size()?.into();
55
56        let chunk_size = params.config.developer.chunk_size;
57
58        let exec = HopWindowExecutor::new(
59            params.actor_context,
60            input,
61            time_col,
62            window_slide,
63            window_size,
64            window_start_exprs,
65            window_end_exprs,
66            output_indices,
67            chunk_size,
68        );
69        Ok((params.info, exec).into())
70    }
71}