risingwave_frontend/optimizer/plan_rewriter/
plan_cloner.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 std::marker::PhantomData;
16
17use crate::PlanRef;
18use crate::optimizer::plan_node::{ConventionMarker, PlanTreeNode};
19use crate::optimizer::plan_rewriter::PlanRewriter;
20
21#[derive(Debug, Clone)]
22pub struct PlanCloner<C: ConventionMarker>(PhantomData<C>);
23
24impl<C: ConventionMarker> PlanCloner<C> {
25    pub fn clone_whole_plan(plan: PlanRef<C>) -> PlanRef<C> {
26        let mut plan_cloner = PlanCloner(PhantomData);
27        plan.rewrite_with(&mut plan_cloner)
28    }
29}
30
31impl<C: ConventionMarker> PlanRewriter<C> for PlanCloner<C> {
32    fn rewrite_with_inputs(&mut self, plan: &PlanRef<C>, inputs: Vec<PlanRef<C>>) -> PlanRef<C> {
33        plan.clone_with_inputs(&inputs)
34    }
35}