@@ -26,12 +26,13 @@ use arrow_flight::sql::{
2626 CommandGetSqlInfo , CommandGetTableTypes , CommandGetTables , CommandGetXdbcTypeInfo ,
2727 CommandPreparedStatementQuery , CommandStatementQuery , SqlInfo , TicketStatementQuery ,
2828} ;
29- use arrow_flight:: { Action , FlightDescriptor , FlightEndpoint , FlightInfo , IpcMessage , SchemaAsIpc , Ticket } ;
30- use datafusion:: arrow:: ipc:: writer:: IpcWriteOptions ;
31- use datafusion:: arrow:: error:: ArrowError ;
32- use prost:: bytes:: Bytes ;
29+ use arrow_flight:: {
30+ Action , FlightDescriptor , FlightEndpoint , FlightInfo , IpcMessage , SchemaAsIpc , Ticket ,
31+ } ;
3332use color_eyre:: Result ;
3433use datafusion:: arrow:: datatypes:: Schema ;
34+ use datafusion:: arrow:: error:: ArrowError ;
35+ use datafusion:: arrow:: ipc:: writer:: IpcWriteOptions ;
3536use datafusion:: logical_expr:: LogicalPlan ;
3637use datafusion:: prelude:: { col, lit} ;
3738use datafusion:: sql:: parser:: DFParser ;
@@ -41,6 +42,7 @@ use futures::{StreamExt, TryStreamExt};
4142use jiff:: Timestamp ;
4243use log:: { debug, error, info} ;
4344use metrics:: { counter, histogram} ;
45+ use prost:: bytes:: Bytes ;
4446use prost:: Message ;
4547use std:: collections:: HashMap ;
4648use std:: str:: FromStr ;
@@ -373,15 +375,14 @@ impl FlightSqlService for FlightSqlServiceImpl {
373375
374376 async fn get_flight_info_table_types (
375377 & self ,
376- _query : CommandGetTableTypes ,
378+ _query : CommandGetTableTypes ,
377379 request : Request < FlightDescriptor > ,
378380 ) -> Result < Response < FlightInfo > , Status > {
379381 counter ! ( "requests" , "endpoint" => "get_flight_info_table_types" ) . increment ( 1 ) ;
380382 let start = Timestamp :: now ( ) ;
381383 let request_id = uuid:: Uuid :: new_v4 ( ) ;
382- let query =
383- "SELECT DISTINCT table_type FROM information_schema.tables ORDER BY table_type"
384- . to_string ( ) ;
384+ let query = "SELECT DISTINCT table_type FROM information_schema.tables ORDER BY table_type"
385+ . to_string ( ) ;
385386 let res = self . create_flight_info ( query, request_id, request) . await ;
386387
387388 // TODO: Move recording to after response is sent to not impact response latency
@@ -600,7 +601,9 @@ impl FlightSqlService for FlightSqlServiceImpl {
600601 } ;
601602
602603 {
603- let mut guard = self . prepared_statements . lock ( )
604+ let mut guard = self
605+ . prepared_statements
606+ . lock ( )
604607 . map_err ( |_| Status :: internal ( "Failed to acquire lock on prepared statements" ) ) ?;
605608 guard. insert ( request_id, handle) ;
606609
@@ -612,7 +615,9 @@ impl FlightSqlService for FlightSqlServiceImpl {
612615 let options = IpcWriteOptions :: default ( ) ;
613616 let IpcMessage ( dataset_schema_bytes) = SchemaAsIpc :: new ( & dataset_schema, & options)
614617 . try_into ( )
615- . map_err ( |e : ArrowError | Status :: internal ( format ! ( "Failed to serialize schema: {}" , e) ) ) ?;
618+ . map_err ( |e : ArrowError | {
619+ Status :: internal ( format ! ( "Failed to serialize schema: {}" , e) )
620+ } ) ?;
616621
617622 // Build response
618623 let result = ActionCreatePreparedStatementResult {
@@ -623,7 +628,8 @@ impl FlightSqlService for FlightSqlServiceImpl {
623628
624629 // Record metrics
625630 let duration = Timestamp :: now ( ) - start;
626- histogram ! ( "do_action_create_prepared_statement_latency_ms" ) . record ( duration. get_milliseconds ( ) as f64 ) ;
631+ histogram ! ( "do_action_create_prepared_statement_latency_ms" )
632+ . record ( duration. get_milliseconds ( ) as f64 ) ;
627633
628634 #[ cfg( feature = "observability" ) ]
629635 {
@@ -637,7 +643,12 @@ impl FlightSqlService for FlightSqlServiceImpl {
637643 rows : None ,
638644 status : 0 ,
639645 } ;
640- if let Err ( e) = self . execution . observability ( ) . try_record_request ( ctx, req) . await {
646+ if let Err ( e) = self
647+ . execution
648+ . observability ( )
649+ . try_record_request ( ctx, req)
650+ . await
651+ {
641652 error ! ( "Error recording request: {}" , e) ;
642653 }
643654 }
@@ -654,18 +665,24 @@ impl FlightSqlService for FlightSqlServiceImpl {
654665 let start = Timestamp :: now ( ) ;
655666
656667 let handle_bytes = query. prepared_statement_handle . to_vec ( ) ;
657- let request_id = Uuid :: from_slice ( & handle_bytes)
658- . map_err ( |e| Status :: invalid_argument ( format ! ( "Invalid prepared statement handle: {}" , e) ) ) ?;
668+ let request_id = Uuid :: from_slice ( & handle_bytes) . map_err ( |e| {
669+ Status :: invalid_argument ( format ! ( "Invalid prepared statement handle: {}" , e) )
670+ } ) ?;
659671
660672 debug ! ( "Closing prepared statement: {}" , request_id) ;
661673
662674 // Remove from storage
663675 {
664- let mut guard = self . prepared_statements . lock ( )
676+ let mut guard = self
677+ . prepared_statements
678+ . lock ( )
665679 . map_err ( |_| Status :: internal ( "Failed to acquire lock on prepared statements" ) ) ?;
666680
667681 if guard. remove ( & request_id) . is_none ( ) {
668- return Err ( Status :: not_found ( format ! ( "Prepared statement not found: {}" , request_id) ) ) ;
682+ return Err ( Status :: not_found ( format ! (
683+ "Prepared statement not found: {}" ,
684+ request_id
685+ ) ) ) ;
669686 }
670687
671688 // Update active prepared statements gauge
@@ -674,7 +691,8 @@ impl FlightSqlService for FlightSqlServiceImpl {
674691
675692 // Record metrics
676693 let duration = Timestamp :: now ( ) - start;
677- histogram ! ( "do_action_close_prepared_statement_latency_ms" ) . record ( duration. get_milliseconds ( ) as f64 ) ;
694+ histogram ! ( "do_action_close_prepared_statement_latency_ms" )
695+ . record ( duration. get_milliseconds ( ) as f64 ) ;
678696
679697 #[ cfg( feature = "observability" ) ]
680698 {
@@ -688,7 +706,12 @@ impl FlightSqlService for FlightSqlServiceImpl {
688706 rows : None ,
689707 status : 0 ,
690708 } ;
691- if let Err ( e) = self . execution . observability ( ) . try_record_request ( ctx, req) . await {
709+ if let Err ( e) = self
710+ . execution
711+ . observability ( )
712+ . try_record_request ( ctx, req)
713+ . await
714+ {
692715 error ! ( "Error recording request: {}" , e) ;
693716 }
694717 }
@@ -710,16 +733,21 @@ impl FlightSqlService for FlightSqlServiceImpl {
710733 Status :: invalid_argument ( format ! ( "Invalid prepared statement handle: {}" , e) )
711734 } ) ?;
712735
713- debug ! ( "Getting flight info for prepared statement: {}" , handle_uuid) ;
736+ debug ! (
737+ "Getting flight info for prepared statement: {}" ,
738+ handle_uuid
739+ ) ;
714740
715741 // Look up the prepared statement
716742 let prepared_stmt = {
717- let guard = self . prepared_statements . lock ( )
743+ let guard = self
744+ . prepared_statements
745+ . lock ( )
718746 . map_err ( |_| Status :: internal ( "Failed to acquire lock on prepared statements" ) ) ?;
719747
720- guard. get ( & handle_uuid)
721- . cloned ( )
722- . ok_or_else ( || Status :: not_found ( format ! ( "Prepared statement not found: {}" , handle_uuid ) ) ) ?
748+ guard. get ( & handle_uuid) . cloned ( ) . ok_or_else ( || {
749+ Status :: not_found ( format ! ( "Prepared statement not found: {}" , handle_uuid ) )
750+ } ) ?
723751 } ;
724752
725753 // Create a new request ID for this execution
@@ -745,9 +773,18 @@ impl FlightSqlService for FlightSqlServiceImpl {
745773 start_ms : start. as_millisecond ( ) ,
746774 duration_ms : duration. get_milliseconds ( ) ,
747775 rows : None ,
748- status : if res. is_ok ( ) { 0 } else { tonic:: Code :: Internal as u16 } ,
776+ status : if res. is_ok ( ) {
777+ 0
778+ } else {
779+ tonic:: Code :: Internal as u16
780+ } ,
749781 } ;
750- if let Err ( e) = self . execution . observability ( ) . try_record_request ( ctx, req) . await {
782+ if let Err ( e) = self
783+ . execution
784+ . observability ( )
785+ . try_record_request ( ctx, req)
786+ . await
787+ {
751788 error ! ( "Error recording request: {}" , e) ;
752789 }
753790 }
@@ -772,9 +809,12 @@ impl FlightSqlService for FlightSqlServiceImpl {
772809 // The request_id in the ticket should correspond to a logical plan in the requests HashMap
773810 // that was created by get_flight_info_prepared_statement
774811 let res = self
775- . do_get_statement_handler ( request_id. clone ( ) , TicketStatementQuery {
776- statement_handle : query. prepared_statement_handle ,
777- } )
812+ . do_get_statement_handler (
813+ request_id. clone ( ) ,
814+ TicketStatementQuery {
815+ statement_handle : query. prepared_statement_handle ,
816+ } ,
817+ )
778818 . await ;
779819
780820 // Record observability
@@ -792,9 +832,18 @@ impl FlightSqlService for FlightSqlServiceImpl {
792832 start_ms : start. as_millisecond ( ) ,
793833 duration_ms : duration. get_milliseconds ( ) ,
794834 rows : None ,
795- status : if res. is_ok ( ) { 0 } else { tonic:: Code :: Internal as u16 } ,
835+ status : if res. is_ok ( ) {
836+ 0
837+ } else {
838+ tonic:: Code :: Internal as u16
839+ } ,
796840 } ;
797- if let Err ( e) = self . execution . observability ( ) . try_record_request ( ctx, req) . await {
841+ if let Err ( e) = self
842+ . execution
843+ . observability ( )
844+ . try_record_request ( ctx, req)
845+ . await
846+ {
798847 error ! ( "Error recording request: {}" , e) ;
799848 }
800849 }
0 commit comments