crepererum commented on code in PR #3789: URL: https://github.com/apache/arrow-rs/pull/3789#discussion_r1126644770
########## arrow-flight/src/bin/flight_sql_client.rs: ########## @@ -0,0 +1,200 @@ +// 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::{sync::Arc, time::Duration}; + +use arrow::error::Result; +use arrow::util::pretty::pretty_format_batches; +use arrow_array::RecordBatch; +use arrow_flight::{ + sql::client::FlightSqlServiceClient, utils::flight_data_to_batches, FlightData, +}; +use arrow_schema::{ArrowError, Schema}; +use clap::Parser; +use futures::TryStreamExt; +use tonic::transport::{ClientTlsConfig, Endpoint}; +use tracing_log::log::info; + +/// A ':' separated key value pair +#[derive(Debug, Clone)] +struct KeyValue<K, V> { + pub key: K, + pub value: V, +} + +impl<K, V> std::str::FromStr for KeyValue<K, V> +where + K: std::str::FromStr, + V: std::str::FromStr, + K::Err: std::fmt::Display, + V::Err: std::fmt::Display, +{ + type Err = String; + + fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { + let parts = s.splitn(2, ':').collect::<Vec<_>>(); + match parts.as_slice() { + [key, value] => { + let key = K::from_str(key).map_err(|e| e.to_string())?; + let value = V::from_str(value).map_err(|e| e.to_string())?; + Ok(Self { key, value }) + } + _ => Err(format!( + "Invalid key value pair - expected 'KEY:VALUE' got '{s}'" + )), + } + } +} + +#[derive(Debug, Parser)] +struct ClientArgs { + /// Additional headers. + /// + /// Values should be key value pairs separated by ':' + #[clap(long, value_delimiter = ',')] + headers: Vec<KeyValue<String, String>>, + + /// Username + #[clap(long)] + username: Option<String>, + + /// Password + #[clap(long)] + password: Option<String>, + + /// Auth token. + #[clap(long)] + token: Option<String>, + + /// Use TLS. + #[clap(long)] + tls: bool, + + /// Server host. + #[clap(long)] + host: String, + + /// Server port. + #[clap(long)] + port: Option<u16>, +} + +#[derive(Debug, Parser)] +struct Args { + /// Client args. + #[clap(flatten)] + client_args: ClientArgs, + + /// SQL query. + #[clap()] Review Comment: done -- 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]
