wangfenjin commented on a change in pull request #1386: URL: https://github.com/apache/arrow-rs/pull/1386#discussion_r823572998
########## File path: arrow-flight/src/sql/server.rs ########## @@ -0,0 +1,637 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::pin::Pin; + +use futures::Stream; +use prost::Message; +use tonic::{Request, Response, Status, Streaming}; + +use super::{ + super::{ + flight_service_server::FlightService, Action, ActionType, Criteria, Empty, + FlightData, FlightDescriptor, FlightInfo, HandshakeRequest, HandshakeResponse, + PutResult, SchemaResult, Ticket, + }, + ActionClosePreparedStatementRequest, ActionCreatePreparedStatementRequest, + CommandGetCatalogs, CommandGetCrossReference, CommandGetDbSchemas, + CommandGetExportedKeys, CommandGetImportedKeys, CommandGetPrimaryKeys, + CommandGetSqlInfo, CommandGetTableTypes, CommandGetTables, + CommandPreparedStatementQuery, CommandPreparedStatementUpdate, CommandStatementQuery, + CommandStatementUpdate, ProstAnyExt, SqlInfo, TicketStatementQuery, +}; + +static CREATE_PREPARED_STATEMENT: &str = "CreatePreparedStatement"; +static CLOSE_PREPARED_STATEMENT: &str = "ClosePreparedStatement"; + +/// Implements FlightSqlService to handle the flight sql protocol +#[tonic::async_trait] +pub trait FlightSqlService: + std::marker::Sync + std::marker::Send + std::marker::Sized + 'static +{ + /// When impl FlightSqlService, you can always set FlightService to Self + type FlightService: FlightService; + + /// Get a FlightInfo for executing a SQL query. + async fn get_flight_info_statement( + &self, + query: CommandStatementQuery, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo for executing an already created prepared statement. + async fn get_flight_info_prepared_statement( + &self, + query: CommandPreparedStatementQuery, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo for listing catalogs. + async fn get_flight_info_catalogs( + &self, + query: CommandGetCatalogs, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo for listing schemas. + async fn get_flight_info_schemas( + &self, + query: CommandGetDbSchemas, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo for listing tables. + async fn get_flight_info_tables( + &self, + query: CommandGetTables, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo to extract information about the table types. + async fn get_flight_info_table_types( + &self, + query: CommandGetTableTypes, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo for retrieving other information (See SqlInfo). + async fn get_flight_info_sql_info( + &self, + query: CommandGetSqlInfo, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo to extract information about primary and foreign keys. + async fn get_flight_info_primary_keys( + &self, + query: CommandGetPrimaryKeys, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo to extract information about exported keys. + async fn get_flight_info_exported_keys( + &self, + query: CommandGetExportedKeys, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo to extract information about imported keys. + async fn get_flight_info_imported_keys( + &self, + query: CommandGetImportedKeys, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + /// Get a FlightInfo to extract information about cross reference. + async fn get_flight_info_cross_reference( + &self, + query: CommandGetCrossReference, + request: FlightDescriptor, + ) -> Result<Response<FlightInfo>, Status>; + + // do_get + + /// Get a FlightInfo for executing an already created prepared statement. + async fn do_get_statement( + &self, + ticket: TicketStatementQuery, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the prepared statement query results. + async fn do_get_prepared_statement( + &self, + query: CommandPreparedStatementQuery, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the list of catalogs. + async fn do_get_catalogs( + &self, + query: CommandGetCatalogs, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the list of schemas. + async fn do_get_schemas( + &self, + query: CommandGetDbSchemas, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the list of tables. + async fn do_get_tables( + &self, + query: CommandGetTables, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; Review comment: I checked the logic again, we can do that but I think not necessary. If we want it be easy to construct a FlightData, we may provide from utility methods like we did in [here](https://github.com/wangfenjin/arrow-rs/blob/flight-sql/arrow-flight/src/lib.rs#L246). Some system already return FlightData or Arrow Schema/RecordBatch, if we force to return Vec of String, user might need to do the converting and then we convert it again. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
