You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "NiwakaDev (via GitHub)" <gi...@apache.org> on 2023/07/30 13:51:17 UTC

[GitHub] [arrow-datafusion] NiwakaDev opened a new pull request, #7138: feat: allow `datafusion-cli` to accept multiple statements

NiwakaDev opened a new pull request, #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #6793.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   This PR allows `datafusion-cli` to accept multiple statements.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] r4ntix commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "r4ntix (via GitHub)" <gi...@apache.org>.
r4ntix commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1280076942


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,30 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let task_ctx = ctx.task_ctx();
+    let dialect = &task_ctx.session_config().options().sql_parser.dialect;
+    let dialect = dialect_from_str(dialect).ok_or_else(|| {
+        DataFusionError::Plan(format!(
+            "Unsupported SQL dialect: {dialect}. Available dialects: \
+                 Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
+                 MsSQL, ClickHouse, BigQuery, Ansi."
+        ))
+    })?;
+    let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
+    for statement in statements {
+        let plan = ctx.state().statement_to_plan(statement).await?;
+        let df = match &plan {
+            LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
+                create_external_table(ctx, cmd).await?;
+                ctx.execute_logical_plan(plan).await?
+            }
+            _ => ctx.execute_logical_plan(plan).await?,
+        };
 
-    let results = df.collect().await?;
-    print_options.print_batches(&results, now)?;
+        let results = df.collect().await?;
+        print_options.print_batches(&results, now)?;
+        println!();

Review Comment:
   The `println!();` here I would suggest to put in the code of `fn print_timing_info()`. Because it will affect the output of `--quiet` mode.
   
   suggestion:
   ```rust
   fn print_timing_info(row_count: usize, now: Instant) {
       println!(
           "{} {} in set. Query took {:.3} seconds.\n",
           row_count,
           if row_count == 1 { "row" } else { "rows" },
           now.elapsed().as_secs_f64()
       );
   }
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#issuecomment-1663918661

   Thanks again everyone -- this is a great contributon @NiwakaDev 🦾 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] NiwakaDev commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "NiwakaDev (via GitHub)" <gi...@apache.org>.
NiwakaDev commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1279924919


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   Done. Please let me know if there are any errors or omissions.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1279862084


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   I am not sure what you mean by the current context -- which one are you thinking of?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] NiwakaDev commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "NiwakaDev (via GitHub)" <gi...@apache.org>.
NiwakaDev commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1281233109


##########
datafusion-cli/tests/cli_integration.rs:
##########
@@ -33,6 +33,10 @@ fn init() {
     ["--command", "select 1", "--format", "json", "-q"],
     "[{\"Int64(1)\":1}]\n"
 )]
+#[case::exec_multiple_statements(
+    ["--command", "select 1; select 2;", "--format", "json", "-q"],
+    "[{\"Int64(1)\":1}]\n[{\"Int64(2)\":2}]\n"
+)]

Review Comment:
   This is a new integration test.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] r4ntix commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "r4ntix (via GitHub)" <gi...@apache.org>.
r4ntix commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1280076942


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,30 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let task_ctx = ctx.task_ctx();
+    let dialect = &task_ctx.session_config().options().sql_parser.dialect;
+    let dialect = dialect_from_str(dialect).ok_or_else(|| {
+        DataFusionError::Plan(format!(
+            "Unsupported SQL dialect: {dialect}. Available dialects: \
+                 Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
+                 MsSQL, ClickHouse, BigQuery, Ansi."
+        ))
+    })?;
+    let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
+    for statement in statements {
+        let plan = ctx.state().statement_to_plan(statement).await?;
+        let df = match &plan {
+            LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
+                create_external_table(ctx, cmd).await?;
+                ctx.execute_logical_plan(plan).await?
+            }
+            _ => ctx.execute_logical_plan(plan).await?,
+        };
 
-    let results = df.collect().await?;
-    print_options.print_batches(&results, now)?;
+        let results = df.collect().await?;
+        print_options.print_batches(&results, now)?;
+        println!();

Review Comment:
   The `println!();` here I would suggest to put in the code of `fn print_timing_info()`. Because it will affect the output of `--quiet` mode.
   
   suggestion:
   ```rust
   // add '\n' at the end of `println!`
   fn print_timing_info(row_count: usize, now: Instant) {
       println!(
           "{} {} in set. Query took {:.3} seconds.\n",
           row_count,
           if row_count == 1 { "row" } else { "rows" },
           now.elapsed().as_secs_f64()
       );
   }
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] r4ntix commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "r4ntix (via GitHub)" <gi...@apache.org>.
r4ntix commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1281673618


##########
datafusion-cli/tests/cli_integration.rs:
##########
@@ -33,6 +33,10 @@ fn init() {
     ["--command", "select 1", "--format", "json", "-q"],
     "[{\"Int64(1)\":1}]\n"
 )]
+#[case::exec_multiple_statements(
+    ["--command", "select 1; select 2;", "--format", "json", "-q"],
+    "[{\"Int64(1)\":1}]\n[{\"Int64(2)\":2}]\n"
+)]

Review Comment:
   ❤️ Thanks again @NiwakaDev -- I like it



##########
datafusion-cli/tests/cli_integration.rs:
##########
@@ -33,6 +33,10 @@ fn init() {
     ["--command", "select 1", "--format", "json", "-q"],
     "[{\"Int64(1)\":1}]\n"
 )]
+#[case::exec_multiple_statements(
+    ["--command", "select 1; select 2;", "--format", "json", "-q"],
+    "[{\"Int64(1)\":1}]\n[{\"Int64(2)\":2}]\n"
+)]

Review Comment:
   ❤️ Thanks again @NiwakaDev -- I like it



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] NiwakaDev commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "NiwakaDev (via GitHub)" <gi...@apache.org>.
NiwakaDev commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1281232640


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,30 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let task_ctx = ctx.task_ctx();
+    let dialect = &task_ctx.session_config().options().sql_parser.dialect;
+    let dialect = dialect_from_str(dialect).ok_or_else(|| {
+        DataFusionError::Plan(format!(
+            "Unsupported SQL dialect: {dialect}. Available dialects: \
+                 Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
+                 MsSQL, ClickHouse, BigQuery, Ansi."
+        ))
+    })?;
+    let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
+    for statement in statements {
+        let plan = ctx.state().statement_to_plan(statement).await?;
+        let df = match &plan {
+            LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
+                create_external_table(ctx, cmd).await?;
+                ctx.execute_logical_plan(plan).await?
+            }
+            _ => ctx.execute_logical_plan(plan).await?,
+        };
 
-    let results = df.collect().await?;
-    print_options.print_batches(&results, now)?;
+        let results = df.collect().await?;
+        print_options.print_batches(&results, now)?;
+        println!();

Review Comment:
   Done. Please let me know if there are any errors or omissions.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] NiwakaDev commented on pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "NiwakaDev (via GitHub)" <gi...@apache.org>.
NiwakaDev commented on PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#issuecomment-1661221168

   Right now I guess that the integration tests pass, and I added a new integration test to them.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1279892014


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   ```
   DataFusion CLI v28.0.0
   ❯ set datafusion.sql_parser.dialect = 'Postgres';
   ```
   I'm referring to this option, it can be found in `ctx.state()...`, and be used to parse statements



##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   ```
   DataFusion CLI v28.0.0
   ❯ set datafusion.sql_parser.dialect = 'Postgres';
   ```
   I'm referring to this option, it can be found in `ctx.state()...`, and be used to parse statements



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1280017694


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   Looks good to me, thank you!



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#issuecomment-1660999801

   🤔  something happened to make CI fail. Perhaps that is what @r4ntix 's comments are about


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] r4ntix commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "r4ntix (via GitHub)" <gi...@apache.org>.
r4ntix commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1280079574


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,30 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let task_ctx = ctx.task_ctx();
+    let dialect = &task_ctx.session_config().options().sql_parser.dialect;
+    let dialect = dialect_from_str(dialect).ok_or_else(|| {
+        DataFusionError::Plan(format!(
+            "Unsupported SQL dialect: {dialect}. Available dialects: \
+                 Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
+                 MsSQL, ClickHouse, BigQuery, Ansi."
+        ))
+    })?;
+    let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
+    for statement in statements {
+        let plan = ctx.state().statement_to_plan(statement).await?;
+        let df = match &plan {
+            LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
+                create_external_table(ctx, cmd).await?;
+                ctx.execute_logical_plan(plan).await?
+            }
+            _ => ctx.execute_logical_plan(plan).await?,
+        };
 
-    let results = df.collect().await?;
-    print_options.print_batches(&results, now)?;
+        let results = df.collect().await?;
+        print_options.print_batches(&results, now)?;
+        println!();

Review Comment:
   The current `--quiet` mode output is as follows:
   ```shell
   ./target/debug/datafusion-cli --command 'select 1;select 2;' -q --format json
   [{"Int64(1)":1}]
   [{"Int64(2)":2}]
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1279829768


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,20 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let statements = DFParser::parse_sql(&sql)?;

Review Comment:
   This will use the default dialect, we can use `parse_sql_with_dialect()` and pass the dialect from the current context into it.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] r4ntix commented on a diff in pull request #7138: feat: allow `datafusion-cli` to accept multiple statements

Posted by "r4ntix (via GitHub)" <gi...@apache.org>.
r4ntix commented on code in PR #7138:
URL: https://github.com/apache/arrow-datafusion/pull/7138#discussion_r1280076942


##########
datafusion-cli/src/exec.rs:
##########
@@ -192,17 +193,30 @@ async fn exec_and_print(
     let now = Instant::now();
 
     let sql = unescape_input(&sql)?;
-    let plan = ctx.state().create_logical_plan(&sql).await?;
-    let df = match &plan {
-        LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
-            create_external_table(ctx, cmd).await?;
-            ctx.execute_logical_plan(plan).await?
-        }
-        _ => ctx.execute_logical_plan(plan).await?,
-    };
+    let task_ctx = ctx.task_ctx();
+    let dialect = &task_ctx.session_config().options().sql_parser.dialect;
+    let dialect = dialect_from_str(dialect).ok_or_else(|| {
+        DataFusionError::Plan(format!(
+            "Unsupported SQL dialect: {dialect}. Available dialects: \
+                 Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
+                 MsSQL, ClickHouse, BigQuery, Ansi."
+        ))
+    })?;
+    let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
+    for statement in statements {
+        let plan = ctx.state().statement_to_plan(statement).await?;
+        let df = match &plan {
+            LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
+                create_external_table(ctx, cmd).await?;
+                ctx.execute_logical_plan(plan).await?
+            }
+            _ => ctx.execute_logical_plan(plan).await?,
+        };
 
-    let results = df.collect().await?;
-    print_options.print_batches(&results, now)?;
+        let results = df.collect().await?;
+        print_options.print_batches(&results, now)?;
+        println!();

Review Comment:
   The `println!();` here I would suggest to put in the code for `fn print_timing_info()`. Because it will affect the output of `--quiet` mode.
   
   suggestion:
   ```rust
   fn print_timing_info(row_count: usize, now: Instant) {
       println!(
           "{} {} in set. Query took {:.3} seconds.\n",
           row_count,
           if row_count == 1 { "row" } else { "rows" },
           now.elapsed().as_secs_f64()
       );
   }
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org