Skip to main content

rustfs_s3select_api/server/
dbms.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;
16
17use crate::{
18    QueryResult,
19    query::{
20        Query,
21        execution::{Output, QueryStateMachineRef},
22        logical_planner::Plan,
23        session::QueryAdmission,
24    },
25};
26
27pub struct QueryHandle {
28    query: Query,
29    result: Output,
30}
31
32impl QueryHandle {
33    pub fn new(query: Query, result: Output) -> Self {
34        Self { query, result }
35    }
36
37    pub fn query(&self) -> &Query {
38        &self.query
39    }
40
41    pub fn result(self) -> Output {
42        self.result
43    }
44}
45
46#[async_trait]
47pub trait DatabaseManagerSystem {
48    fn try_reserve_query(&self) -> QueryResult<QueryAdmission> {
49        Ok(QueryAdmission::unmanaged())
50    }
51
52    async fn execute(&self, query: &Query) -> QueryResult<QueryHandle>;
53
54    async fn execute_admitted(&self, query: &Query, _admission: QueryAdmission) -> QueryResult<QueryHandle> {
55        self.execute(query).await
56    }
57
58    async fn build_query_state_machine(&self, query: Query) -> QueryResult<QueryStateMachineRef>;
59    async fn build_logical_plan(&self, query_state_machine: QueryStateMachineRef) -> QueryResult<Option<Plan>>;
60    async fn execute_logical_plan(
61        &self,
62        logical_plan: Plan,
63        query_state_machine: QueryStateMachineRef,
64    ) -> QueryResult<QueryHandle>;
65}