11use arrow_array:: RecordBatch ;
22use arrow_flight:: {
3- FlightInfo , flight_service_client:: FlightServiceClient , sql:: client:: FlightSqlServiceClient ,
3+ FlightInfo , error:: FlightError , flight_service_client:: FlightServiceClient ,
4+ sql:: client:: FlightSqlServiceClient ,
45} ;
56use arrow_schema:: ArrowError ;
67use futures:: TryStreamExt ;
@@ -29,11 +30,11 @@ impl Session {
2930 endpoint : Endpoint ,
3031 is_repl : bool ,
3132 args : Args ,
32- ) -> Result < Self , ArrowError > {
33+ ) -> Result < Self , FlightError > {
3334 let channel = endpoint
3435 . connect ( )
3536 . await
36- . map_err ( |err| ArrowError :: IpcError ( err . to_string ( ) ) ) ?;
37+ . map_err ( |err| FlightError :: ExternalError ( Box :: new ( err ) ) ) ?;
3738
3839 if is_repl {
3940 println ! ( "Welcome to Arrow CLI v{}." , env!( "CARGO_PKG_VERSION" ) ) ;
@@ -106,7 +107,7 @@ impl Session {
106107 if let Err ( e) = async {
107108 let result = self . execute_query ( & query) . await ?;
108109 print_query_result ( & result, & self . args ) ?;
109- Ok :: < _ , ArrowError > ( ( ) )
110+ Ok :: < _ , FlightError > ( ( ) )
110111 }
111112 . await
112113 {
@@ -124,7 +125,7 @@ impl Session {
124125 if let Err ( e) = async {
125126 let result = self . execute_query ( command) . await ?;
126127 print_query_result ( & result, & self . args ) ?;
127- Ok :: < _ , ArrowError > ( ( ) )
128+ Ok :: < _ , FlightError > ( ( ) )
128129 }
129130 . await
130131 {
@@ -134,13 +135,12 @@ impl Session {
134135
135136 pub async fn handle_stdin ( & mut self ) {
136137 let mut lines = std:: io:: stdin ( ) . lock ( ) . lines ( ) ;
137- // TODO support multi line
138138 while let Some ( Ok ( line) ) = lines. next ( ) {
139139 let line = line. trim_end ( ) ;
140140 if let Err ( e) = async {
141141 let result = self . execute_query ( line) . await ?;
142142 print_query_result ( & result, & self . args ) ?;
143- Ok :: < _ , ArrowError > ( ( ) )
143+ Ok :: < _ , FlightError > ( ( ) )
144144 }
145145 . await
146146 {
@@ -149,7 +149,7 @@ impl Session {
149149 }
150150 }
151151
152- async fn execute_query ( & mut self , query : & str ) -> Result < QueryResult , ArrowError > {
152+ async fn execute_query ( & mut self , query : & str ) -> Result < QueryResult , FlightError > {
153153 let start = Instant :: now ( ) ;
154154 let flight_info = if self . args . prepared {
155155 let mut stmt = self . client . prepare ( query. to_string ( ) , None ) . await ?;
@@ -167,15 +167,15 @@ impl Session {
167167 let ticket = endpoint
168168 . ticket
169169 . as_ref ( )
170- . ok_or_else ( || ArrowError :: IpcError ( "Ticket is emtpy" . to_string ( ) ) ) ?
170+ . ok_or_else ( || {
171+ FlightError :: Arrow ( ArrowError :: IpcError ( "Ticket is emtpy" . to_string ( ) ) )
172+ } ) ?
171173 . clone ( ) ;
172174 let mut client = self . client . clone ( ) ;
173175 handles. push ( tokio:: spawn ( async move {
174176 let flight_data = client. do_get ( ticket) . await ?;
175- let result: Vec < RecordBatch > = flight_data. try_collect ( ) . await . map_err ( |e| {
176- ArrowError :: IpcError ( format ! ( "Failed to collect record batches: {e}" ) )
177- } ) ?;
178- Ok :: < Vec < RecordBatch > , ArrowError > ( result)
177+ let result: Vec < RecordBatch > = flight_data. try_collect ( ) . await ?;
178+ Ok :: < Vec < RecordBatch > , FlightError > ( result)
179179 } ) ) ;
180180 }
181181
0 commit comments