From 91b09680c0cb25fbc727784a38515479d03f1efc Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Fri, 30 Jun 2023 15:03:43 +0100 Subject: [PATCH] Add default implementations to the FlightSqlService trait The trait currently does not have many default implementations, but it does have a lot of methods. This PR adds default implementations for all methods returning Status::unimplemented to fix #4372 --- arrow-flight/src/sql/server.rs | 222 +++++++++++++++++++++++++++------ 1 file changed, 185 insertions(+), 37 deletions(-) diff --git a/arrow-flight/src/sql/server.rs b/arrow-flight/src/sql/server.rs index f599fbca46a5..e2d804fc1d80 100644 --- a/arrow-flight/src/sql/server.rs +++ b/arrow-flight/src/sql/server.rs @@ -89,91 +89,143 @@ pub trait FlightSqlService: Sync + Send + Sized + 'static { &self, query: CommandStatementQuery, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_statement has no default implementation", + )) + } /// Get a FlightInfo for executing a substrait plan. async fn get_flight_info_substrait_plan( &self, query: CommandStatementSubstraitPlan, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_substrait_plan has no default implementation", + )) + } /// Get a FlightInfo for executing an already created prepared statement. async fn get_flight_info_prepared_statement( &self, query: CommandPreparedStatementQuery, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_prepared_statement has no default implementation", + )) + } /// Get a FlightInfo for listing catalogs. async fn get_flight_info_catalogs( &self, query: CommandGetCatalogs, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_catalogs has no default implementation", + )) + } /// Get a FlightInfo for listing schemas. async fn get_flight_info_schemas( &self, query: CommandGetDbSchemas, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_schemas has no default implementation", + )) + } /// Get a FlightInfo for listing tables. async fn get_flight_info_tables( &self, query: CommandGetTables, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_tables has no default implementation", + )) + } /// Get a FlightInfo to extract information about the table types. async fn get_flight_info_table_types( &self, query: CommandGetTableTypes, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_table_types has no default implementation", + )) + } /// Get a FlightInfo for retrieving other information (See SqlInfo). async fn get_flight_info_sql_info( &self, query: CommandGetSqlInfo, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_sql_info has no default implementation", + )) + } /// Get a FlightInfo to extract information about primary and foreign keys. async fn get_flight_info_primary_keys( &self, query: CommandGetPrimaryKeys, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_primary_keys has no default implementation", + )) + } /// Get a FlightInfo to extract information about exported keys. async fn get_flight_info_exported_keys( &self, query: CommandGetExportedKeys, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_exported_keys has no default implementation", + )) + } /// Get a FlightInfo to extract information about imported keys. async fn get_flight_info_imported_keys( &self, query: CommandGetImportedKeys, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_imported_keys has no default implementation", + )) + } /// Get a FlightInfo to extract information about cross reference. async fn get_flight_info_cross_reference( &self, query: CommandGetCrossReference, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_cross_reference has no default implementation", + )) + } /// Get a FlightInfo to extract information about the supported XDBC types. async fn get_flight_info_xdbc_type_info( &self, query: CommandGetXdbcTypeInfo, request: Request, - ) -> Result, Status>; + ) -> Result, Status> { + Err(Status::unimplemented( + "get_flight_info_xdbc_type_info has no default implementation", + )) + } // do_get @@ -182,84 +234,132 @@ pub trait FlightSqlService: Sync + Send + Sized + 'static { &self, ticket: TicketStatementQuery, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_statement has no default implementation", + )) + } /// Get a FlightDataStream containing the prepared statement query results. async fn do_get_prepared_statement( &self, query: CommandPreparedStatementQuery, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_prepared_statement has no default implementation", + )) + } /// Get a FlightDataStream containing the list of catalogs. async fn do_get_catalogs( &self, query: CommandGetCatalogs, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_catalogs has no default implementation", + )) + } /// Get a FlightDataStream containing the list of schemas. async fn do_get_schemas( &self, query: CommandGetDbSchemas, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_schemas has no default implementation", + )) + } /// Get a FlightDataStream containing the list of tables. async fn do_get_tables( &self, query: CommandGetTables, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_tables has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the table types. async fn do_get_table_types( &self, query: CommandGetTableTypes, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_table_types has no default implementation", + )) + } /// Get a FlightDataStream containing the list of SqlInfo results. async fn do_get_sql_info( &self, query: CommandGetSqlInfo, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_sql_info has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the primary and foreign keys. async fn do_get_primary_keys( &self, query: CommandGetPrimaryKeys, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_primary_keys has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the exported keys. async fn do_get_exported_keys( &self, query: CommandGetExportedKeys, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_exported_keys has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the imported keys. async fn do_get_imported_keys( &self, query: CommandGetImportedKeys, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_imported_keys has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the cross reference. async fn do_get_cross_reference( &self, query: CommandGetCrossReference, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_cross_reference has no default implementation", + )) + } /// Get a FlightDataStream containing the data related to the supported XDBC types. async fn do_get_xdbc_type_info( &self, query: CommandGetXdbcTypeInfo, request: Request, - ) -> Result::DoGetStream>, Status>; + ) -> Result::DoGetStream>, Status> { + Err(Status::unimplemented( + "do_get_xdbc_type_info has no default implementation", + )) + } // do_put @@ -280,28 +380,44 @@ pub trait FlightSqlService: Sync + Send + Sized + 'static { &self, ticket: CommandStatementUpdate, request: Request>, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_put_statement_update has no default implementation", + )) + } /// Bind parameters to given prepared statement. async fn do_put_prepared_statement_query( &self, query: CommandPreparedStatementQuery, request: Request>, - ) -> Result::DoPutStream>, Status>; + ) -> Result::DoPutStream>, Status> { + Err(Status::unimplemented( + "do_put_prepared_statement_query has no default implementation", + )) + } /// Execute an update SQL prepared statement. async fn do_put_prepared_statement_update( &self, query: CommandPreparedStatementUpdate, request: Request>, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_put_prepared_statement_update has no default implementation", + )) + } /// Execute a substrait plan async fn do_put_substrait_plan( &self, query: CommandStatementSubstraitPlan, request: Request>, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_put_substrait_plan has no default implementation", + )) + } // do_action @@ -326,56 +442,88 @@ pub trait FlightSqlService: Sync + Send + Sized + 'static { &self, query: ActionCreatePreparedStatementRequest, request: Request, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_action_create_prepared_statement has no default implementation", + )) + } /// Close a prepared statement. async fn do_action_close_prepared_statement( &self, query: ActionClosePreparedStatementRequest, request: Request, - ) -> Result<(), Status>; + ) -> Result<(), Status> { + Err(Status::unimplemented( + "do_action_close_prepared_statement has no default implementation", + )) + } /// Create a prepared substrait plan. async fn do_action_create_prepared_substrait_plan( &self, query: ActionCreatePreparedSubstraitPlanRequest, request: Request, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_action_create_prepared_substrait_plan has no default implementation", + )) + } /// Begin a transaction async fn do_action_begin_transaction( &self, query: ActionBeginTransactionRequest, request: Request, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_action_begin_transaction has no default implementation", + )) + } /// End a transaction async fn do_action_end_transaction( &self, query: ActionEndTransactionRequest, request: Request, - ) -> Result<(), Status>; + ) -> Result<(), Status> { + Err(Status::unimplemented( + "do_action_end_transaction has no default implementation", + )) + } /// Begin a savepoint async fn do_action_begin_savepoint( &self, query: ActionBeginSavepointRequest, request: Request, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_action_begin_savepoint has no default implementation", + )) + } /// End a savepoint async fn do_action_end_savepoint( &self, query: ActionEndSavepointRequest, request: Request, - ) -> Result<(), Status>; + ) -> Result<(), Status> { + Err(Status::unimplemented( + "do_action_end_savepoint has no default implementation", + )) + } /// Cancel a query async fn do_action_cancel_query( &self, query: ActionCancelQueryRequest, request: Request, - ) -> Result; + ) -> Result { + Err(Status::unimplemented( + "do_action_cancel_query has no default implementation", + )) + } /// do_exchange