tustvold commented on a change in pull request #1386: URL: https://github.com/apache/arrow-rs/pull/1386#discussion_r822460994
########## File path: arrow-flight/src/sql/server.rs ########## @@ -0,0 +1,585 @@ +// 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 + FlightService + '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>; + + /// Get a FlightDataStream containing the data related to the table types. + async fn do_get_table_types( + &self, + query: CommandGetTableTypes, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the list of SqlInfo results. + async fn do_get_sql_info( + &self, + query: CommandGetSqlInfo, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the data related to the primary and foreign keys. + async fn do_get_primary_keys( + &self, + query: CommandGetPrimaryKeys, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the data related to the exported keys. + async fn do_get_exported_keys( + &self, + query: CommandGetExportedKeys, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the data related to the imported keys. + async fn do_get_imported_keys( + &self, + query: CommandGetImportedKeys, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + /// Get a FlightDataStream containing the data related to the cross reference. + async fn do_get_cross_reference( + &self, + query: CommandGetCrossReference, + ) -> Result<Response<<Self as FlightService>::DoGetStream>, Status>; + + // do_put + + /// Execute an update SQL statement. + async fn do_put_statement_update( + &self, + ticket: CommandStatementUpdate, + ) -> Result<Response<<Self as FlightService>::DoPutStream>, Status>; + + /// Bind parameters to given prepared statement. + async fn do_put_prepared_statement_query( + &self, + query: CommandPreparedStatementQuery, + ) -> Result<Response<<Self as FlightService>::DoPutStream>, Status>; + + /// Execute an update SQL prepared statement. + async fn do_put_prepared_statement_update( + &self, + query: CommandPreparedStatementUpdate, + ) -> Result<Response<<Self as FlightService>::DoPutStream>, Status>; + + // do_action + + /// Create a prepared statement from given SQL statement. + async fn do_action_create_prepared_statement( + &self, + query: ActionCreatePreparedStatementRequest, + ) -> Result<Response<<Self as FlightService>::DoActionStream>, Status>; + + /// Close a prepared statement. + async fn do_action_close_prepared_statement( + &self, + query: ActionClosePreparedStatementRequest, + ) -> Result<Response<<Self as FlightService>::DoActionStream>, Status>; + + /// Register a new SqlInfo result, making it available when calling GetSqlInfo. + async fn register_sql_info(&self, id: i32, result: &SqlInfo); +} + +/// Implements the lower level interface to handle FlightSQL +#[tonic::async_trait] +impl<T: 'static> FlightService for T +where + T: FlightSqlService + std::marker::Sync + std::marker::Send, +{ + type HandshakeStream = Pin< + Box<dyn Stream<Item = Result<HandshakeResponse, Status>> + Send + Sync + 'static>, Review comment: A Sync object can have member functions that return non-Sync objects? There is no real reason for a stream to be Sync as it can only be consumed through a mutable reference -- 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]
