@@ -13,22 +13,20 @@ use std::io::BufRead;
1313use tokio:: time:: Instant ;
1414use tonic:: transport:: { Channel , Endpoint } ;
1515
16- use crate :: helper:: CliHelper ;
16+ use crate :: { Args , helper:: CliHelper } ;
1717
1818pub struct Session {
1919 client : FlightSqlServiceClient < Channel > ,
2020 is_repl : bool ,
2121 prompt : String ,
22- prepared : bool ,
22+ args : Args ,
2323}
2424
2525impl Session {
2626 pub async fn try_new (
2727 endpoint : Endpoint ,
28- user : & str ,
29- password : & str ,
3028 is_repl : bool ,
31- prepared : bool ,
29+ args : Args ,
3230 ) -> Result < Self , ArrowError > {
3331 let channel = endpoint
3432 . connect ( )
@@ -37,21 +35,21 @@ impl Session {
3735
3836 if is_repl {
3937 println ! ( "Welcome to Arrow CLI v{}." , env!( "CARGO_PKG_VERSION" ) ) ;
40- println ! ( "Connecting to {} as user {}." , endpoint. uri( ) , user) ;
38+ println ! ( "Connecting to {} as user {}." , endpoint. uri( ) , args . user) ;
4139 println ! ( ) ;
4240 }
4341
4442 let mut client = FlightSqlServiceClient :: new_from_inner (
4543 FlightServiceClient :: new ( channel) . max_decoding_message_size ( usize:: MAX ) ,
4644 ) ;
47- let _token = client. handshake ( user, password) . await ?;
45+ let _token = client. handshake ( & args . user , & args . password ) . await ?;
4846
4947 let prompt = format ! ( "{} :) " , endpoint. uri( ) . host( ) . unwrap( ) ) ;
5048 Ok ( Self {
5149 client,
5250 is_repl,
5351 prompt,
54- prepared ,
52+ args ,
5553 } )
5654 }
5755
@@ -130,7 +128,7 @@ impl Session {
130128 }
131129
132130 let start = Instant :: now ( ) ;
133- let flight_info = if self . prepared {
131+ let flight_info = if self . args . prepared {
134132 let mut stmt = self . client . prepare ( query. to_string ( ) , None ) . await ?;
135133 let info = stmt. execute ( ) . await ?;
136134 stmt. close ( ) . await ?;
@@ -142,7 +140,7 @@ impl Session {
142140 let mut batches: Vec < RecordBatch > = Vec :: new ( ) ;
143141
144142 let mut handles = Vec :: with_capacity ( flight_info. endpoint . len ( ) ) ;
145- for endpoint in flight_info. endpoint {
143+ for endpoint in flight_info. endpoint . iter ( ) {
146144 let ticket = endpoint
147145 . ticket
148146 . as_ref ( )
@@ -166,17 +164,20 @@ impl Session {
166164 if is_repl {
167165 let res = pretty_format_batches ( batches. as_slice ( ) ) ?;
168166
169- println ! ( "{res}" ) ;
170- println ! ( ) ;
167+ println ! ( "{res}\n " ) ;
168+
169+ if self . args . print_schema {
170+ let schema = flight_info. try_decode_schema ( ) ?;
171+ println ! ( "{schema:#?}\n " ) ;
172+ }
171173
172174 let rows: usize = batches. iter ( ) . map ( |b| b. num_rows ( ) ) . sum ( ) ;
173175 println ! (
174- "{} rows in set (tickets received in {:.3} sec, rows received in {:.3} sec)" ,
176+ "{} rows in set (tickets received in {:.3} sec, rows received in {:.3} sec)\n " ,
175177 rows,
176178 ticket_recv_duration. as_secs_f64( ) ,
177179 rows_recv_duration. as_secs_f64( ) ,
178180 ) ;
179- println ! ( ) ;
180181 } else {
181182 let res = print_batches_with_sep ( batches. as_slice ( ) , b'\t' ) ?;
182183 print ! ( "{res}" ) ;
0 commit comments