Skip to main content

risingwave_stream/from_proto/
changelog.rs

1// Copyright 2024 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_pb::stream_plan::ChangeLogNode;
16use risingwave_pb::stream_plan::change_log_node::Mode;
17use risingwave_storage::StateStore;
18
19use super::ExecutorBuilder;
20use crate::error::StreamResult;
21use crate::executor::{ChangeLogExecutor, ChangeLogMode, Executor};
22use crate::task::ExecutorParams;
23
24pub struct ChangeLogExecutorBuilder;
25
26impl_stream_node_body!(Changelog(ChangeLogNode) => ChangeLogExecutorBuilder);
27
28impl ExecutorBuilder for ChangeLogExecutorBuilder {
29    type Node = ChangeLogNode;
30
31    async fn new_boxed_executor(
32        params: ExecutorParams,
33        node: &Self::Node,
34        _store: impl StateStore,
35    ) -> StreamResult<Executor> {
36        let [input]: [_; 1] = params.input.try_into().unwrap();
37
38        let vnodes = params.vnode_bitmap;
39        let vnode_count = params.actor_context.vnode_count;
40        let distribution_keys = node
41            .distribution_keys
42            .iter()
43            .map(|k| *k as usize)
44            .collect::<Vec<_>>();
45        let mode = match &node.mode {
46            None => ChangeLogMode::Normal,
47            Some(Mode::Keyed(_)) => ChangeLogMode::Keyed,
48        };
49        let stream_keys = node.stream_keys.iter().map(|&k| k as usize).collect();
50        let exec = ChangeLogExecutor::new(
51            params.actor_context,
52            input,
53            node.need_op,
54            vnode_count,
55            vnodes,
56            mode,
57            distribution_keys,
58            stream_keys,
59        );
60        Ok((params.info, exec).into())
61    }
62}