servers/query_handler/
sql.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 common_query::Output;
19use datafusion_expr::LogicalPlan;
20use query::parser::PromQuery;
21use query::query_engine::DescribeResult;
22use session::context::QueryContextRef;
23use sql::statements::statement::Statement;
24
25use crate::error::Result;
26
27pub type ServerSqlQueryHandlerRef = Arc<dyn SqlQueryHandler + Send + Sync>;
28
29#[async_trait]
30pub trait SqlQueryHandler {
31    async fn do_query(&self, query: &str, query_ctx: QueryContextRef) -> Vec<Result<Output>>;
32
33    async fn do_exec_plan(
34        &self,
35        stmt: Option<Statement>,
36        plan: LogicalPlan,
37        query_ctx: QueryContextRef,
38    ) -> Result<Output>;
39
40    async fn do_promql_query(
41        &self,
42        query: &PromQuery,
43        query_ctx: QueryContextRef,
44    ) -> Vec<Result<Output>>;
45
46    async fn do_describe(
47        &self,
48        stmt: Statement,
49        query_ctx: QueryContextRef,
50    ) -> Result<Option<DescribeResult>>;
51
52    async fn is_valid_schema(&self, catalog: &str, schema: &str) -> Result<bool>;
53}