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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 8fcdf48e Support parsing `EXPLAIN ESTIMATE` of Clickhouse (#1605)
8fcdf48e is described below

commit 8fcdf48e5c8325e0fdea2c5b2948bda69ba9b907
Author: cjw <[email protected]>
AuthorDate: Tue Dec 17 23:03:12 2024 +0800

    Support parsing `EXPLAIN ESTIMATE` of Clickhouse (#1605)
    
    Co-authored-by: Kermit <[email protected]>
---
 src/ast/mod.rs            |  7 +++++++
 src/keywords.rs           |  1 +
 src/parser/mod.rs         |  4 ++++
 tests/sqlparser_common.rs | 30 ++++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index ccb2ed1b..6e3f2047 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -3239,6 +3239,9 @@ pub enum Statement {
         ///
         /// [SQLite](https://sqlite.org/lang_explain.html)
         query_plan: bool,
+        /// `EXPLAIN ESTIMATE`
+        /// 
[Clickhouse](https://clickhouse.com/docs/en/sql-reference/statements/explain#explain-estimate)
+        estimate: bool,
         /// A SQL query that specifies what to explain
         statement: Box<Statement>,
         /// Optional output format of explain
@@ -3471,6 +3474,7 @@ impl fmt::Display for Statement {
                 verbose,
                 analyze,
                 query_plan,
+                estimate,
                 statement,
                 format,
                 options,
@@ -3483,6 +3487,9 @@ impl fmt::Display for Statement {
                 if *analyze {
                     write!(f, "ANALYZE ")?;
                 }
+                if *estimate {
+                    write!(f, "ESTIMATE ")?;
+                }
 
                 if *verbose {
                     write!(f, "VERBOSE ")?;
diff --git a/src/keywords.rs b/src/keywords.rs
index 7e335407..bbfd00ca 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -298,6 +298,7 @@ define_keywords!(
     ERROR,
     ESCAPE,
     ESCAPED,
+    ESTIMATE,
     EVENT,
     EVERY,
     EXCEPT,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index ca46bb60..94d63cf8 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -9091,6 +9091,7 @@ impl<'a> Parser<'a> {
         let mut analyze = false;
         let mut verbose = false;
         let mut query_plan = false;
+        let mut estimate = false;
         let mut format = None;
         let mut options = None;
 
@@ -9103,6 +9104,8 @@ impl<'a> Parser<'a> {
             options = Some(self.parse_utility_options()?)
         } else if self.parse_keywords(&[Keyword::QUERY, Keyword::PLAN]) {
             query_plan = true;
+        } else if self.parse_keyword(Keyword::ESTIMATE) {
+            estimate = true;
         } else {
             analyze = self.parse_keyword(Keyword::ANALYZE);
             verbose = self.parse_keyword(Keyword::VERBOSE);
@@ -9120,6 +9123,7 @@ impl<'a> Parser<'a> {
                 analyze,
                 verbose,
                 query_plan,
+                estimate,
                 statement: Box::new(statement),
                 format,
                 options,
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 0f1813c2..1bf9383a 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -4375,6 +4375,7 @@ fn run_explain_analyze(
             analyze,
             verbose,
             query_plan,
+            estimate,
             statement,
             format,
             options,
@@ -4384,6 +4385,7 @@ fn run_explain_analyze(
             assert_eq!(format, expected_format);
             assert_eq!(options, exepcted_options);
             assert!(!query_plan);
+            assert!(!estimate);
             assert_eq!("SELECT sqrt(id) FROM foo", statement.to_string());
         }
         _ => panic!("Unexpected Statement, must be Explain"),
@@ -4528,6 +4530,34 @@ fn parse_explain_query_plan() {
     );
 }
 
+#[test]
+fn parse_explain_estimate() {
+    let statement = all_dialects().verified_stmt("EXPLAIN ESTIMATE SELECT 
sqrt(id) FROM foo");
+
+    match &statement {
+        Statement::Explain {
+            query_plan,
+            estimate,
+            analyze,
+            verbose,
+            statement,
+            ..
+        } => {
+            assert!(estimate);
+            assert!(!query_plan);
+            assert!(!analyze);
+            assert!(!verbose);
+            assert_eq!("SELECT sqrt(id) FROM foo", statement.to_string());
+        }
+        _ => unreachable!(),
+    }
+
+    assert_eq!(
+        "EXPLAIN ESTIMATE SELECT sqrt(id) FROM foo",
+        statement.to_string()
+    );
+}
+
 #[test]
 fn parse_named_argument_function() {
     let dialects = all_dialects_where(|d| {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to