|
62 | 62 | } |
63 | 63 | } |
64 | 64 |
|
65 | | - pub fn statement_to_plan(&self, statement: DFStatement) -> Result<LogicalPlan> { |
66 | | - match statement { |
67 | | - DFStatement::Statement(s) => self.sql_statement_to_plan(*s), |
68 | | - _ => self.inner.statement_to_plan(statement), |
69 | | - } |
70 | | - } |
71 | | - |
72 | 65 | /// Custom implementation of `sql_statement_to_plan` |
73 | 66 | pub fn sql_statement_to_plan(&self, statement: Statement) -> Result<LogicalPlan> { |
74 | 67 | // Check for a custom statement type |
|
85 | 78 | } |
86 | 79 |
|
87 | 80 | /// Handle custom statements not supported by the original `SqlToRel` |
| 81 | + #[allow(clippy::too_many_lines)] |
88 | 82 | fn handle_custom_statement(&self, statement: Statement) -> Result<LogicalPlan> { |
89 | 83 | let planner_context: &mut PlannerContext = &mut PlannerContext::new(); |
90 | 84 | // Example: Custom handling for a specific statement |
|
95 | 89 | | Statement::Update { .. } => Ok(LogicalPlan::default()), |
96 | 90 | Statement::ShowSchemas { .. } => self.show_variable_to_plan(&["schemas".into()]), |
97 | 91 | Statement::ShowVariable { variable } => self.show_variable_to_plan(&variable), |
| 92 | + Statement::ShowObjects { |
| 93 | + terse: _, |
| 94 | + show_options, |
| 95 | + } => { |
| 96 | + let Some(show_in) = show_options.show_in else { |
| 97 | + return plan_err!("Unsupported show statement: missing show_in"); |
| 98 | + }; |
| 99 | + let Some(parent_name) = show_in.parent_name else { |
| 100 | + return plan_err!("Unsupported show statement: missing parent_name"); |
| 101 | + }; |
| 102 | + self.show_objects_to_plan(&parent_name) |
| 103 | + } |
98 | 104 | Statement::Drop { |
99 | 105 | object_type, |
100 | 106 | if_exists, |
@@ -232,6 +238,40 @@ where |
232 | 238 | } |
233 | 239 | } |
234 | 240 |
|
| 241 | + fn show_objects_to_plan(&self, parent: &ObjectName) -> Result<LogicalPlan> { |
| 242 | + // Only support listing objects in schema for now |
| 243 | + match parent.0.len() { |
| 244 | + 2 => { |
| 245 | + let (catalog, schema) = (parent.0[0].value.clone(), parent.0[1].value.clone()); |
| 246 | + |
| 247 | + // Create query to list objects in schema |
| 248 | + let columns = [ |
| 249 | + "table_catalog as 'database_name'", |
| 250 | + "table_schema as 'schema_name'", |
| 251 | + "table_name as 'name'", |
| 252 | + "case when table_type='BASE TABLE' then 'TABLE' else table_type end as 'kind'", |
| 253 | + "null as 'comment'", |
| 254 | + ] |
| 255 | + .join(", "); |
| 256 | + // TODO: views? |
| 257 | + // TODO: Return programmatically constructed plan |
| 258 | + let query = format!("SELECT {columns} FROM information_schema.tables where table_schema = '{schema}' and table_catalog = '{catalog}'"); |
| 259 | + let mut statements = DFParser::parse_sql(query.as_str())?; |
| 260 | + statements.pop_front().map_or_else( |
| 261 | + || plan_err!("Failed to parse SQL statement"), |
| 262 | + |statement| { |
| 263 | + if let DFStatement::Statement(s) = statement { |
| 264 | + self.sql_statement_to_plan(*s) |
| 265 | + } else { |
| 266 | + plan_err!("Failed to parse SQL statement") |
| 267 | + } |
| 268 | + }, |
| 269 | + ) |
| 270 | + } |
| 271 | + _ => plan_err!("Unsupported show objects: {:?}", parent), |
| 272 | + } |
| 273 | + } |
| 274 | + |
235 | 275 | fn show_variable_to_plan(&self, variable: &[Ident]) -> Result<LogicalPlan> { |
236 | 276 | //println!("SHOW variable: {:?}", variable); |
237 | 277 | if !self.inner.has_table("information_schema", "df_settings") { |
|
0 commit comments