Skip to main content

query/dist_plan/analyzer/
fallback.rs

1// Copyright 2023 Greptime Team
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
15//! Fallback dist plan analyzer, which will only push down table scan node
16//! This is used when `PlanRewriter` produce errors when trying to rewrite the plan
17//! This is a temporary solution, and will be removed once we have a more robust plan rewriter
18//!
19
20use datafusion_common::Result as DfResult;
21use datafusion_common::tree_node::{Transformed, TreeNodeRewriter};
22use datafusion_expr::LogicalPlan;
23
24use crate::dist_plan::MergeScanLogicalPlan;
25
26/// FallbackPlanRewriter is a plan rewriter that will only push down table scan node
27/// This is used when `PlanRewriter` produce errors when trying to rewrite the plan
28/// This is a temporary solution, and will be removed once we have a more robust plan rewriter
29/// It will traverse the logical plan and rewrite table scan node to merge scan node
30#[derive(Debug, Clone, Default)]
31pub struct FallbackPlanRewriter;
32
33impl TreeNodeRewriter for FallbackPlanRewriter {
34    type Node = LogicalPlan;
35
36    fn f_down(
37        &mut self,
38        plan: Self::Node,
39    ) -> DfResult<datafusion_common::tree_node::Transformed<Self::Node>> {
40        if matches!(plan, LogicalPlan::TableScan(_)) {
41            let node = MergeScanLogicalPlan::new(plan, false).into_logical_plan();
42            Ok(Transformed::yes(node))
43        } else {
44            Ok(Transformed::no(plan))
45        }
46    }
47}