Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sqlparser-0.21] Changes to planning for SHOW TABLES #3193

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion datafusion/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
59 changes: 40 additions & 19 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down