Skip to main content

query/range_select/
planner.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
15use std::sync::Arc;
16
17use async_trait::async_trait;
18use datafusion::catalog::Session;
19use datafusion::error::Result as DfResult;
20use datafusion::logical_expr::physical_planning_context::PhysicalPlanningContext;
21use datafusion::logical_expr::{LogicalPlan, UserDefinedLogicalNode};
22use datafusion::physical_plan::ExecutionPlan;
23use datafusion::physical_planner::{ExtensionPlanner, PhysicalPlanner};
24
25use crate::range_select::plan::RangeSelect;
26
27pub struct RangeSelectPlanner;
28
29#[async_trait]
30impl ExtensionPlanner for RangeSelectPlanner {
31    async fn plan_extension(
32        &self,
33        _planner: &dyn PhysicalPlanner,
34        node: &dyn UserDefinedLogicalNode,
35        logical_inputs: &[&LogicalPlan],
36        physical_inputs: &[Arc<dyn ExecutionPlan>],
37        session: &dyn Session,
38        planning_ctx: &PhysicalPlanningContext,
39    ) -> DfResult<Option<Arc<dyn ExecutionPlan>>> {
40        if let Some(node) = node.as_any().downcast_ref::<RangeSelect>() {
41            Ok(Some(node.to_execution_plan(
42                logical_inputs[0],
43                physical_inputs[0].clone(),
44                session,
45                planning_ctx,
46            )?))
47        } else {
48            Ok(None)
49        }
50    }
51}