servers/query_handler/
grpc.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::pin::Pin;
16use std::sync::Arc;
17
18use api::v1::greptime_request::Request;
19use async_trait::async_trait;
20use common_base::AffectedRows;
21use common_grpc::flight::do_put::DoPutResponse;
22use common_query::Output;
23use futures::Stream;
24use session::context::QueryContextRef;
25use table::TableRef;
26
27use crate::error::Result;
28use crate::grpc::flight::{PutRecordBatchRequest, PutRecordBatchRequestStream};
29
30pub type ServerGrpcQueryHandlerRef = Arc<dyn GrpcQueryHandler + Send + Sync>;
31
32pub type RawRecordBatch = bytes::Bytes;
33
34#[async_trait]
35pub trait GrpcQueryHandler {
36    async fn do_query(&self, query: Request, ctx: QueryContextRef) -> Result<Output>;
37
38    async fn put_record_batch(
39        &self,
40        request: PutRecordBatchRequest,
41        table_ref: &mut Option<TableRef>,
42        ctx: QueryContextRef,
43    ) -> Result<AffectedRows>;
44
45    fn handle_put_record_batch_stream(
46        &self,
47        stream: PutRecordBatchRequestStream,
48        ctx: QueryContextRef,
49    ) -> Pin<Box<dyn Stream<Item = Result<DoPutResponse>> + Send>>;
50}