From e4e9b7167453a8c45bc0523460647e7507c0ca41 Mon Sep 17 00:00:00 2001 From: Guillem Borrell Date: Tue, 17 Jan 2023 11:50:32 +0000 Subject: [PATCH] Read csv from stdin too --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 77f06c4..5a6695f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,11 @@ fn main() { .about("Read csv, output arrow stream") .arg(arg!([path] "Path to CSV file")) .arg(arg!(-d --delimiter "Column delimiter. Assume ,").required(false)) + .arg( + arg!(-i --stdin ... "Read from stdin") + .required(false) + .action(ArgAction::SetTrue), + ) .arg(arg!(-q --query "Execute query on the file").required(false)) .arg( arg!(-s --summary ... "Summarize the data") @@ -97,7 +102,7 @@ fn main() { Command::new("wpq") .about("Write to a paquet file") .arg( - arg!(-t --text ... "Output text instead of binary") + arg!(-t --text ... "Input text instead of binary") .required(false) .action(ArgAction::SetTrue), ) @@ -106,7 +111,12 @@ fn main() { .get_matches(); if let Some(_matches) = matches.subcommand_matches("csv") { if let Some(path) = _matches.get_one::("path") { - let mut ldf = io::read_csv(path.to_string()); + let mut ldf = LazyFrame::default(); + if _matches.get_flag("stdin") { + ldf = io::load_csv_from_stdin(); + } else { + ldf = io::read_csv(path.to_string()); + } if let Some(query) = _matches.get_one::("query") { ldf = sql::execute(ldf, query); }