You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by dh...@apache.org on 2021/05/08 07:07:25 UTC

[arrow-datafusion] branch master updated: add param validation for datafusion-cli (#284)

This is an automated email from the ASF dual-hosted git repository.

dheres pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new a947f11  add param validation for datafusion-cli (#284)
a947f11 is described below

commit a947f11a8c0558c7301931a6c35a07de396d2463
Author: Jiayu Liu <Ji...@users.noreply.github.com>
AuthorDate: Sat May 8 15:07:19 2021 +0800

    add param validation for datafusion-cli (#284)
    
    * add param validation for datafusion-cli
    
    * Update datafusion-cli/src/main.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
    
    * Update datafusion-cli/src/main.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
 datafusion-cli/src/main.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs
index dd7265e..6a7693a 100644
--- a/datafusion-cli/src/main.rs
+++ b/datafusion-cli/src/main.rs
@@ -40,6 +40,7 @@ pub async fn main() {
                 .help("Path to your data, default to current directory")
                 .short("p")
                 .long("data-path")
+                .validator(is_valid_data_dir)
                 .takes_value(true),
         )
         .arg(
@@ -47,6 +48,7 @@ pub async fn main() {
                 .help("The batch size of each query, or use DataFusion default")
                 .short("c")
                 .long("batch-size")
+                .validator(is_valid_batch_size)
                 .takes_value(true),
         )
         .get_matches();
@@ -100,6 +102,21 @@ pub async fn main() {
     rl.save_history(".history").ok();
 }
 
+fn is_valid_data_dir(dir: String) -> std::result::Result<(), String> {
+    if Path::new(&dir).is_dir() {
+        Ok(())
+    } else {
+        Err(format!("Invalid data directory '{}'", dir))
+    }
+}
+
+fn is_valid_batch_size(size: String) -> std::result::Result<(), String> {
+    match size.parse::<usize>() {
+        Ok(size) if size > 0 => Ok(()),
+        _ => Err(format!("Invalid batch size '{}'", size)),
+    }
+}
+
 fn is_exit_command(line: &str) -> bool {
     let line = line.trim_end().to_lowercase();
     line == "quit" || line == "exit"