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

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


The following commit(s) were added to refs/heads/sqlparser-0.21 by this push:
     new 8801986bd Changes to planning for SHOW TABLES due to changes in 
sqlparser (#3193)
8801986bd is described below

commit 8801986bd9709dc032c35f3b1907b090afc3cfda
Author: Andy Grove <[email protected]>
AuthorDate: Thu Aug 18 12:53:59 2022 -0600

    Changes to planning for SHOW TABLES due to changes in sqlparser (#3193)
---
 datafusion/common/Cargo.toml  |  2 +-
 datafusion/core/Cargo.toml    |  2 +-
 datafusion/expr/Cargo.toml    |  2 +-
 datafusion/sql/Cargo.toml     |  2 +-
 datafusion/sql/src/planner.rs | 59 +++++++++++++++++++++++++++++--------------
 5 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/datafusion/common/Cargo.toml b/datafusion/common/Cargo.toml
index 20cb09670..2d7855064 100644
--- a/datafusion/common/Cargo.toml
+++ b/datafusion/common/Cargo.toml
@@ -47,4 +47,4 @@ ordered-float = "3.0"
 parquet = { version = "20.0.0", features = ["arrow"], optional = true }
 pyo3 = { version = "0.16", optional = true }
 serde_json = "1.0"
-sqlparser = "0.20"
+sqlparser = { git = "https://github.com/sqlparser-rs/sqlparser-rs";, rev = 
"18881f8fcf611cb5dabfacf4d1b76c680c846b81" }
diff --git a/datafusion/core/Cargo.toml b/datafusion/core/Cargo.toml
index 189e53d63..9e6b8714a 100644
--- a/datafusion/core/Cargo.toml
+++ b/datafusion/core/Cargo.toml
@@ -85,7 +85,7 @@ pyo3 = { version = "0.16", optional = true }
 rand = "0.8"
 rayon = { version = "1.5", optional = true }
 smallvec = { version = "1.6", features = ["union"] }
-sqlparser = "0.20"
+sqlparser = { git = "https://github.com/sqlparser-rs/sqlparser-rs";, rev = 
"18881f8fcf611cb5dabfacf4d1b76c680c846b81" }
 tempfile = "3"
 tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", 
"sync", "fs", "parking_lot"] }
 tokio-stream = "0.1"
diff --git a/datafusion/expr/Cargo.toml b/datafusion/expr/Cargo.toml
index 6d368c63c..49d89a1e9 100644
--- a/datafusion/expr/Cargo.toml
+++ b/datafusion/expr/Cargo.toml
@@ -38,4 +38,4 @@ path = "src/lib.rs"
 ahash = { version = "0.8", default-features = false, features = 
["runtime-rng"] }
 arrow = { version = "20.0.0", features = ["prettyprint"] }
 datafusion-common = { path = "../common", version = "11.0.0" }
-sqlparser = "0.20"
+sqlparser = { git = "https://github.com/sqlparser-rs/sqlparser-rs";, rev = 
"18881f8fcf611cb5dabfacf4d1b76c680c846b81" }
diff --git a/datafusion/sql/Cargo.toml b/datafusion/sql/Cargo.toml
index 6ad1da9e7..f13618299 100644
--- a/datafusion/sql/Cargo.toml
+++ b/datafusion/sql/Cargo.toml
@@ -42,5 +42,5 @@ arrow = { version = "20.0.0", features = ["prettyprint"] }
 datafusion-common = { path = "../common", version = "11.0.0" }
 datafusion-expr = { path = "../expr", version = "11.0.0" }
 hashbrown = "0.12"
-sqlparser = "0.20"
+sqlparser = { git = "https://github.com/sqlparser-rs/sqlparser-rs";, rev = 
"18881f8fcf611cb5dabfacf4d1b76c680c846b81" }
 tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", 
"sync", "fs", "parking_lot"] }
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 28c82f802..64af43e81 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -241,6 +241,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 }))
             }
 
+            Statement::ShowTables {
+                extended,
+                full,
+                db_name,
+                filter,
+            } => self.show_tables_to_plan(extended, full, db_name, filter),
+
             Statement::ShowColumns {
                 extended,
                 full,
@@ -254,6 +261,35 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         }
     }
 
+    /// Generate a logical plan from a "SHOW TABLES" query
+    fn show_tables_to_plan(
+        &self,
+        extended: bool,
+        full: bool,
+        db_name: Option<Ident>,
+        filter: Option<ShowStatementFilter>,
+    ) -> Result<LogicalPlan> {
+        if self.has_table("information_schema", "tables") {
+            // we only support the basic "SHOW TABLES"
+            // https://github.com/apache/arrow-datafusion/issues/3188
+            if db_name.is_some() || filter.is_some() || full || extended {
+                Err(DataFusionError::Plan(
+                    "Unsupported parameters to SHOW TABLES".to_string(),
+                ))
+            } else {
+                let query = "SELECT * FROM information_schema.tables;";
+                let mut rewrite = DFParser::parse_sql(query)?;
+                assert_eq!(rewrite.len(), 1);
+                self.statement_to_plan(rewrite.pop_front().unwrap())
+            }
+        } else {
+            Err(DataFusionError::Plan(
+                "SHOW TABLES is not supported unless information_schema is 
enabled"
+                    .to_string(),
+            ))
+        }
+    }
+
     /// Generate a logical plan from an SQL query
     pub fn query_to_plan(
         &self,
@@ -2261,26 +2297,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
     }
 
     fn show_variable_to_plan(&self, variable: &[Ident]) -> Result<LogicalPlan> 
{
-        // Special case SHOW TABLES
         let variable = ObjectName(variable.to_vec()).to_string();
-        if variable.as_str().eq_ignore_ascii_case("tables") {
-            if self.has_table("information_schema", "tables") {
-                let query = "SELECT * FROM information_schema.tables;";
-                let mut rewrite = DFParser::parse_sql(query)?;
-                assert_eq!(rewrite.len(), 1);
-                self.statement_to_plan(rewrite.pop_front().unwrap())
-            } else {
-                Err(DataFusionError::Plan(
-                    "SHOW TABLES is not supported unless information_schema is 
enabled"
-                        .to_string(),
-                ))
-            }
-        } else {
-            Err(DataFusionError::NotImplemented(format!(
-                "SHOW {} not implemented. Supported syntax: SHOW <TABLES>",
-                variable
-            )))
-        }
+        Err(DataFusionError::NotImplemented(format!(
+            "SHOW {} not implemented. Supported syntax: SHOW <TABLES>",
+            variable
+        )))
     }
 
     fn show_columns_to_plan(

Reply via email to