Skip to main content

rustfs_s3select_api/query/
logical_planner.rs

1// Copyright 2024 RustFS 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 async_trait::async_trait;
16use datafusion::arrow::datatypes::SchemaRef;
17use datafusion::logical_expr::LogicalPlan as DFPlan;
18use std::sync::Arc;
19
20use crate::QueryResult;
21
22use super::ast::ExtStatement;
23use super::session::SessionCtx;
24
25#[derive(Clone)]
26pub enum Plan {
27    // only support query sql
28    /// Query plan
29    Query(QueryPlan),
30}
31
32impl Plan {
33    pub fn schema(&self) -> SchemaRef {
34        match self {
35            Self::Query(p) => Arc::new(p.df_plan.schema().as_arrow().clone()),
36        }
37    }
38}
39
40#[derive(Debug, Clone)]
41pub struct QueryPlan {
42    pub df_plan: DFPlan,
43    pub is_tag_scan: bool,
44}
45
46impl QueryPlan {
47    pub fn is_explain(&self) -> bool {
48        matches!(self.df_plan, DFPlan::Explain(_) | DFPlan::Analyze(_))
49    }
50}
51
52#[async_trait]
53pub trait LogicalPlanner {
54    async fn create_logical_plan(&self, statement: ExtStatement, session: &SessionCtx) -> QueryResult<Plan>;
55}