This is an automated email from the ASF dual-hosted git repository.
jiayuliu pushed a commit to branch upgrade-clap
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/upgrade-clap by this push:
new 51cf9cf upgrade more binaries
51cf9cf is described below
commit 51cf9cfda8c53c8af3b166aecd72d18388d04db1
Author: Jiayu Liu <[email protected]>
AuthorDate: Wed Feb 2 16:55:12 2022 +0800
upgrade more binaries
---
.../src/bin/flight-test-integration-client.rs | 55 +++++++++-------
.../src/bin/flight-test-integration-server.rs | 37 +++++++----
.../flight_client_scenarios/auth_basic_proto.rs | 2 +-
.../flight_client_scenarios/integration_test.rs | 2 +-
.../src/flight_client_scenarios/middleware.rs | 2 +-
integration-testing/src/flight_server_scenarios.rs | 2 +-
.../flight_server_scenarios/auth_basic_proto.rs | 2 +-
.../flight_server_scenarios/integration_test.rs | 2 +-
.../src/flight_server_scenarios/middleware.rs | 2 +-
parquet/src/bin/parquet-read.rs | 75 +++++++++-------------
parquet/src/bin/parquet-rowcount.rs | 36 +++++------
11 files changed, 107 insertions(+), 110 deletions(-)
diff --git a/integration-testing/src/bin/flight-test-integration-client.rs
b/integration-testing/src/bin/flight-test-integration-client.rs
index a765fee..1db893d 100644
--- a/integration-testing/src/bin/flight-test-integration-client.rs
+++ b/integration-testing/src/bin/flight-test-integration-client.rs
@@ -16,40 +16,49 @@
// under the License.
use arrow_integration_testing::flight_client_scenarios;
-
-use clap::{App, Arg};
-
+use clap::Parser;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
+#[derive(clap::ArgEnum, Debug, Clone)]
+enum Scenario {
+ Middleware,
+ AuthBasicProto,
+ Customized,
+}
+
+#[derive(Debug, Parser)]
+#[clap(author, version, about, long_about = None)]
+struct Args {
+ #[clap(long)]
+ host: String,
+ #[clap(long)]
+ port: u16,
+ #[clap(long)]
+ path: String,
+ #[clap(long, arg_enum, default_value_t = Scenario::Customized)]
+ scenario: Scenario,
+}
+
#[tokio::main]
async fn main() -> Result {
#[cfg(feature = "logging")]
tracing_subscriber::fmt::init();
- let matches = App::new("rust flight-test-integration-client")
- .arg(Arg::new("host").long("host").takes_value(true))
- .arg(Arg::new("port").long("port").takes_value(true))
- .arg(Arg::new("path").long("path").takes_value(true))
- .arg(Arg::new("scenario").long("scenario").takes_value(true))
- .get_matches();
-
- let host = matches.value_of("host").expect("Host is required");
- let port = matches.value_of("port").expect("Port is required");
+ let args = Args::parse();
+ let host = args.host;
+ let port = args.port;
- match matches.value_of("scenario") {
- Some("middleware") => {
- flight_client_scenarios::middleware::run_scenario(host,
port).await?
+ match args.scenario {
+ Scenario::Middleware => {
+ flight_client_scenarios::middleware::run_scenario(&host,
port).await?
}
- Some("auth:basic_proto") => {
- flight_client_scenarios::auth_basic_proto::run_scenario(host,
port).await?
+ Scenario::AuthBasicProto => {
+ flight_client_scenarios::auth_basic_proto::run_scenario(&host,
port).await?
}
- Some(scenario_name) => unimplemented!("Scenario not found: {}",
scenario_name),
- None => {
- let path = matches
- .value_of("path")
- .expect("Path is required if scenario is not specified");
- flight_client_scenarios::integration_test::run_scenario(host,
port, path)
+ Scenario::Customized => {
+ let path = args.path;
+ flight_client_scenarios::integration_test::run_scenario(&host,
port, &path)
.await?;
}
}
diff --git a/integration-testing/src/bin/flight-test-integration-server.rs
b/integration-testing/src/bin/flight-test-integration-server.rs
index cbe891e..58461fb 100644
--- a/integration-testing/src/bin/flight-test-integration-server.rs
+++ b/integration-testing/src/bin/flight-test-integration-server.rs
@@ -15,35 +15,44 @@
// specific language governing permissions and limitations
// under the License.
-use clap::{App, Arg};
-
use arrow_integration_testing::flight_server_scenarios;
+use clap::Parser;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
+#[derive(clap::ArgEnum, Debug, Clone)]
+enum Scenario {
+ Middleware,
+ AuthBasicProto,
+ Customized,
+}
+
+#[derive(Debug, Parser)]
+#[clap(author, version, about, long_about = None)]
+struct Args {
+ #[clap(long)]
+ port: u16,
+ #[clap(long, arg_enum, default_value_t = Scenario::Customized)]
+ scenario: Scenario,
+}
+
#[tokio::main]
async fn main() -> Result {
#[cfg(feature = "logging")]
tracing_subscriber::fmt::init();
- let matches = App::new("rust flight-test-integration-server")
- .about("Integration testing server for Flight.")
- .arg(Arg::new("port").long("port").takes_value(true))
- .arg(Arg::new("scenario").long("scenario").takes_value(true))
- .get_matches();
-
- let port = matches.value_of("port").unwrap_or("0");
+ let args = Args::parse();
+ let port = args.port;
- match matches.value_of("scenario") {
- Some("middleware") => {
+ match args.scenario {
+ Scenario::Middleware => {
flight_server_scenarios::middleware::scenario_setup(port).await?
}
- Some("auth:basic_proto") => {
+ Scenario::AuthBasicProto => {
flight_server_scenarios::auth_basic_proto::scenario_setup(port).await?
}
- Some(scenario_name) => unimplemented!("Scenario not found: {}",
scenario_name),
- None => {
+ Scenario::Customized => {
flight_server_scenarios::integration_test::scenario_setup(port).await?;
}
}
diff --git
a/integration-testing/src/flight_client_scenarios/auth_basic_proto.rs
b/integration-testing/src/flight_client_scenarios/auth_basic_proto.rs
index 5e8cd46..ab398d3 100644
--- a/integration-testing/src/flight_client_scenarios/auth_basic_proto.rs
+++ b/integration-testing/src/flight_client_scenarios/auth_basic_proto.rs
@@ -29,7 +29,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;
type Client = FlightServiceClient<tonic::transport::Channel>;
-pub async fn run_scenario(host: &str, port: &str) -> Result {
+pub async fn run_scenario(host: &str, port: u16) -> Result {
let url = format!("http://{}:{}", host, port);
let mut client = FlightServiceClient::connect(url).await?;
diff --git
a/integration-testing/src/flight_client_scenarios/integration_test.rs
b/integration-testing/src/flight_client_scenarios/integration_test.rs
index bf64451..c021020 100644
--- a/integration-testing/src/flight_client_scenarios/integration_test.rs
+++ b/integration-testing/src/flight_client_scenarios/integration_test.rs
@@ -38,7 +38,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;
type Client = FlightServiceClient<tonic::transport::Channel>;
-pub async fn run_scenario(host: &str, port: &str, path: &str) -> Result {
+pub async fn run_scenario(host: &str, port: u16, path: &str) -> Result {
let url = format!("http://{}:{}", host, port);
let client = FlightServiceClient::connect(url).await?;
diff --git a/integration-testing/src/flight_client_scenarios/middleware.rs
b/integration-testing/src/flight_client_scenarios/middleware.rs
index cbca879..db8c42c 100644
--- a/integration-testing/src/flight_client_scenarios/middleware.rs
+++ b/integration-testing/src/flight_client_scenarios/middleware.rs
@@ -24,7 +24,7 @@ use tonic::{Request, Status};
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
-pub async fn run_scenario(host: &str, port: &str) -> Result {
+pub async fn run_scenario(host: &str, port: u16) -> Result {
let url = format!("http://{}:{}", host, port);
let conn = tonic::transport::Endpoint::new(url)?.connect().await?;
let mut client = FlightServiceClient::with_interceptor(conn,
middleware_interceptor);
diff --git a/integration-testing/src/flight_server_scenarios.rs
b/integration-testing/src/flight_server_scenarios.rs
index 9163b69..e56252f 100644
--- a/integration-testing/src/flight_server_scenarios.rs
+++ b/integration-testing/src/flight_server_scenarios.rs
@@ -27,7 +27,7 @@ pub mod middleware;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
-pub async fn listen_on(port: &str) -> Result<SocketAddr> {
+pub async fn listen_on(port: u16) -> Result<SocketAddr> {
let addr: SocketAddr = format!("0.0.0.0:{}", port).parse()?;
let listener = TcpListener::bind(addr).await?;
diff --git
a/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs
b/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs
index 5607b46..68a4a0d 100644
--- a/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs
+++ b/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs
@@ -37,7 +37,7 @@ use prost::Message;
use crate::{AUTH_PASSWORD, AUTH_USERNAME};
-pub async fn scenario_setup(port: &str) -> Result {
+pub async fn scenario_setup(port: u16) -> Result {
let service = AuthBasicProtoScenarioImpl {
username: AUTH_USERNAME.into(),
password: AUTH_PASSWORD.into(),
diff --git
a/integration-testing/src/flight_server_scenarios/integration_test.rs
b/integration-testing/src/flight_server_scenarios/integration_test.rs
index ae370b6..9c9ebd8 100644
--- a/integration-testing/src/flight_server_scenarios/integration_test.rs
+++ b/integration-testing/src/flight_server_scenarios/integration_test.rs
@@ -43,7 +43,7 @@ type TonicStream<T> = Pin<Box<dyn Stream<Item = T> + Send +
Sync + 'static>>;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
-pub async fn scenario_setup(port: &str) -> Result {
+pub async fn scenario_setup(port: u16) -> Result {
let addr = super::listen_on(port).await?;
let service = FlightServiceImpl {
diff --git a/integration-testing/src/flight_server_scenarios/middleware.rs
b/integration-testing/src/flight_server_scenarios/middleware.rs
index 1416acc..5876ac9 100644
--- a/integration-testing/src/flight_server_scenarios/middleware.rs
+++ b/integration-testing/src/flight_server_scenarios/middleware.rs
@@ -31,7 +31,7 @@ type TonicStream<T> = Pin<Box<dyn Stream<Item = T> + Send +
Sync + 'static>>;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;
-pub async fn scenario_setup(port: &str) -> Result {
+pub async fn scenario_setup(port: u16) -> Result {
let service = MiddlewareScenarioImpl {};
let svc = FlightServiceServer::new(service);
let addr = super::listen_on(port).await?;
diff --git a/parquet/src/bin/parquet-read.rs b/parquet/src/bin/parquet-read.rs
index aa3b827..8ffca16 100644
--- a/parquet/src/bin/parquet-read.rs
+++ b/parquet/src/bin/parquet-read.rs
@@ -52,63 +52,46 @@
extern crate parquet;
-use std::{env, fs::File, path::Path};
-
-use clap::{crate_authors, crate_version, App, Arg};
-
+use clap::Parser;
use parquet::file::reader::{FileReader, SerializedFileReader};
use parquet::record::Row;
+use std::{fs::File, path::Path};
+
+#[derive(Debug, Parser)]
+#[clap( author, version, about("Read data from a Parquet file and print output
in console, in either built-in or JSON format"), long_about = None)]
+struct Args {
+ #[clap(long, help("Path to a parquet file"))]
+ file_name: String,
+ #[clap(
+ long,
+ default_value_t = 0_usize,
+ help("Number of records to read. When not provided, all records are
read")
+ )]
+ num_records: usize,
+ #[clap(short, long, help("Print Parquet file in JSON lines format"))]
+ json: bool,
+}
fn main() {
- let app = App::new("parquet-read")
- .version(crate_version!())
- .author(crate_authors!())
- .about("Read data from a Parquet file and print output in console, in
either built-in or JSON format")
- .arg(
- Arg::with_name("file_path")
- .value_name("file-path")
- .required(true)
- .index(1)
- .help("Path to a parquet file"),
- )
- .arg(
- Arg::with_name("num_records")
- .value_name("num-records")
- .index(2)
- .help(
- "Number of records to read. When not provided, all records
are read.",
- ),
- )
- .arg(
- Arg::with_name("json")
- .short("j")
- .long("json")
- .takes_value(false)
- .help("Print Parquet file in JSON lines format"),
- );
+ let args = Args::parse();
- let matches = app.get_matches();
- let filename = matches.value_of("file_path").unwrap();
- let num_records: Option<usize> = if matches.is_present("num_records") {
- match matches.value_of("num_records").unwrap().parse() {
- Ok(value) => Some(value),
- Err(e) => panic!("Error when reading value for [num-records], {}",
e),
- }
- } else {
- None
- };
+ let filename = args.file_name;
+ let num_records = args.num_records;
+ let json = args.json;
- let json = matches.is_present("json");
let path = Path::new(&filename);
- let file = File::open(&path).unwrap();
- let parquet_reader = SerializedFileReader::new(file).unwrap();
+ let file = File::open(&path).expect("Unable to open file");
+ let parquet_reader =
+ SerializedFileReader::new(file).expect("Failed to create reader");
// Use full schema as projected schema
- let mut iter = parquet_reader.get_row_iter(None).unwrap();
+ let mut iter = parquet_reader
+ .get_row_iter(None)
+ .expect("Failed to create row iterator");
let mut start = 0;
- let end = num_records.unwrap_or(0);
- let all_records = num_records.is_none();
+ let end = num_records;
+ let all_records = end == 0;
while all_records || start < end {
match iter.next() {
diff --git a/parquet/src/bin/parquet-rowcount.rs
b/parquet/src/bin/parquet-rowcount.rs
index 3c61bab..3e8da3e 100644
--- a/parquet/src/bin/parquet-rowcount.rs
+++ b/parquet/src/bin/parquet-rowcount.rs
@@ -49,30 +49,26 @@
//! applied.
extern crate parquet;
-
-use std::{env, fs::File, path::Path};
-
-use clap::{crate_authors, crate_version, App, Arg};
-
+use clap::Parser;
use parquet::file::reader::{FileReader, SerializedFileReader};
+use std::{fs::File, path::Path};
+
+#[derive(Debug, Parser)]
+#[clap( author, version, about, long_about = None)]
+struct Args {
+ #[clap(
+ long,
+ multiple_values(true),
+ help("List of Parquet files to read from separated by space")
+ )]
+ file_paths: Vec<String>,
+}
fn main() {
- let matches = App::new("parquet-rowcount")
- .version(crate_version!())
- .author(crate_authors!())
- .about("Return number of rows in Parquet file")
- .arg(
- Arg::with_name("file_paths")
- .value_name("file-paths")
- .required(true)
- .multiple(true)
- .help("List of Parquet files to read from separated by space"),
- )
- .get_matches();
+ let args = Args::parse();
- let filenames: Vec<&str> =
matches.values_of("file_paths").unwrap().collect();
- for filename in &filenames {
- let path = Path::new(filename);
+ for filename in args.file_paths {
+ let path = Path::new(&filename);
let file = File::open(path).unwrap();
let parquet_reader = SerializedFileReader::new(file).unwrap();
let row_group_metadata = parquet_reader.metadata().row_groups();