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

[arrow-datafusion] branch master updated: #1268: allow datafusion-cli to toggle quiet flag within CLI (#1330)

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

jiayuliu 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 e3a682d  #1268: allow datafusion-cli to toggle quiet flag within CLI (#1330)
e3a682d is described below

commit e3a682d732f6a128fe78c921e0162221d843bd23
Author: Javier Goday <jg...@gmail.com>
AuthorDate: Sun Nov 21 08:12:01 2021 +0100

    #1268: allow datafusion-cli to toggle quiet flag within CLI (#1330)
    
    * #1268: allow datafusion-cli to toggle quiet flag within CLI
    
    * Implement quiet_mode in command
---
 datafusion-cli/src/command.rs | 12 ++++++++++--
 datafusion-cli/src/exec.rs    |  6 ++++--
 docs/source/user-guide/cli.md | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/datafusion-cli/src/command.rs b/datafusion-cli/src/command.rs
index 3b4d1c5..39cd5e9 100644
--- a/datafusion-cli/src/command.rs
+++ b/datafusion-cli/src/command.rs
@@ -37,13 +37,14 @@ pub enum Command {
     DescribeTable(String),
     ListFunctions,
     SearchFunctions(String),
+    QuietMode(bool),
 }
 
 impl Command {
     pub async fn execute(
         &self,
         ctx: &mut Context,
-        print_options: &PrintOptions,
+        print_options: &mut PrintOptions,
     ) -> Result<()> {
         let now = Instant::now();
         match self {
@@ -64,6 +65,10 @@ impl Command {
                     .print_batches(&batches, now)
                     .map_err(|e| DataFusionError::Execution(e.to_string()))
             }
+            Self::QuietMode(quiet) => {
+                print_options.quiet = *quiet;
+                Ok(())
+            }
             Self::Quit => Err(DataFusionError::Execution(
                 "Unexpected quit, this should be handled outside".into(),
             )),
@@ -89,17 +94,19 @@ impl Command {
             Self::Help => ("\\?", "help"),
             Self::ListFunctions => ("\\h", "function list"),
             Self::SearchFunctions(_) => ("\\h function", "search function"),
+            Self::QuietMode(_) => ("\\quiet", "set quiet mode"),
         }
     }
 }
 
-const ALL_COMMANDS: [Command; 6] = [
+const ALL_COMMANDS: [Command; 7] = [
     Command::ListTables,
     Command::DescribeTable(String::new()),
     Command::Quit,
     Command::Help,
     Command::ListFunctions,
     Command::SearchFunctions(String::new()),
+    Command::QuietMode(false),
 ];
 
 fn all_commands_info() -> RecordBatch {
@@ -137,6 +144,7 @@ impl FromStr for Command {
             ("?", None) => Self::Help,
             ("h", None) => Self::ListFunctions,
             ("h", Some(function)) => Self::SearchFunctions(function.into()),
+            ("quiet", Some(b)) => Self::QuietMode(b == "true"),
             _ => return Err(()),
         })
     }
diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rs
index 103dd72..41db7e6 100644
--- a/datafusion-cli/src/exec.rs
+++ b/datafusion-cli/src/exec.rs
@@ -84,6 +84,8 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
     rl.set_helper(Some(CliHelper::default()));
     rl.load_history(".history").ok();
 
+    let mut print_options = print_options.clone();
+
     loop {
         match rl.readline("❯ ") {
             Ok(line) if line.starts_with('\\') => {
@@ -92,7 +94,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
                     match cmd {
                         Command::Quit => break,
                         _ => {
-                            if let Err(e) = cmd.execute(ctx, print_options).await {
+                            if let Err(e) = cmd.execute(ctx, &mut print_options).await {
                                 eprintln!("{}", e)
                             }
                         }
@@ -103,7 +105,7 @@ pub async fn exec_from_repl(ctx: &mut Context, print_options: &PrintOptions) {
             }
             Ok(line) => {
                 rl.add_history_entry(line.trim_end());
-                match exec_and_print(ctx, print_options, line).await {
+                match exec_and_print(ctx, &print_options, line).await {
                     Ok(_) => {}
                     Err(err) => eprintln!("{:?}", err),
                 }
diff --git a/docs/source/user-guide/cli.md b/docs/source/user-guide/cli.md
index cb95fba..049573f 100644
--- a/docs/source/user-guide/cli.md
+++ b/docs/source/user-guide/cli.md
@@ -72,3 +72,37 @@ The DataFusion CLI can also connect to a Ballista scheduler for query execution.
 ```bash
 datafusion-cli --host localhost --port 50050
 ```
+
+## Cli commands
+
+Available commands inside DataFusion CLI are:
+
+- Quit
+
+```bash
+> \q
+```
+
+- Help
+
+```bash
+> \?
+```
+
+- ListTables
+
+```bash
+> \d
+```
+
+- DescribeTable
+
+```bash
+> \d table_name
+```
+
+- QuietMode
+
+```
+> \quiet [true|false]
+```