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