Skip to main content

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_grpc::flight::do_put::DoPutResponse;
21use common_query::Output;
22use futures::Stream;
23use session::context::QueryContextRef;
24
25use crate::error::Result;
26use crate::grpc::flight::PutRecordBatchRequestStream;
27
28pub type ServerGrpcQueryHandlerRef = Arc<dyn GrpcQueryHandler + Send + Sync>;
29
30pub type RawRecordBatch = bytes::Bytes;
31
32#[async_trait]
33pub trait GrpcQueryHandler {
34    async fn do_query(&self, query: Request, ctx: QueryContextRef) -> Result<Output>;
35
36    fn handle_put_record_batch_stream(
37        &self,
38        stream: PutRecordBatchRequestStream,
39        ctx: QueryContextRef,
40    ) -> Pin<Box<dyn Stream<Item = Result<DoPutResponse>> + Send>>;
41}