Skip to main content

risingwave_stream/from_proto/
append_only_dedup.rs

1// Copyright 2023 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::sync::Arc;
16
17use risingwave_pb::stream_plan::DedupNode;
18use risingwave_storage::StateStore;
19
20use super::ExecutorBuilder;
21use crate::common::table::state_table::StateTableBuilder;
22use crate::error::StreamResult;
23use crate::executor::{AppendOnlyDedupExecutor, Executor};
24use crate::task::ExecutorParams;
25
26pub struct AppendOnlyDedupExecutorBuilder;
27
28impl_stream_node_body!(AppendOnlyDedup(DedupNode) => AppendOnlyDedupExecutorBuilder);
29
30impl ExecutorBuilder for AppendOnlyDedupExecutorBuilder {
31    type Node = DedupNode;
32
33    async fn new_boxed_executor(
34        params: ExecutorParams,
35        node: &Self::Node,
36        store: impl StateStore,
37    ) -> StreamResult<Executor> {
38        let [input]: [_; 1] = params.input.try_into().unwrap();
39        let table = node.get_state_table()?;
40        let vnodes = Some(Arc::new(params.vnode_bitmap));
41        let state_table = StateTableBuilder::new(table, store, vnodes)
42            .enable_preload_all_rows_by_config(&params.config)
43            .build()
44            .await;
45        // Unlike the stream key, the dedup columns are in the pk order of the state table.
46        let dedup_cols = node
47            .dedup_column_indices
48            .iter()
49            .map(|&idx| idx as usize)
50            .collect();
51        let exec = AppendOnlyDedupExecutor::new(
52            params.actor_context,
53            input,
54            dedup_cols,
55            state_table,
56            params.watermark_epoch,
57            params.executor_stats.clone(),
58        );
59        Ok((params.info, exec).into())
60    }
61}