@@ -30,7 +30,6 @@ use datafusion::sql::sqlparser::ast::{
3030 DataType as SQLDataType , Statement ,
3131} ;
3232use datafusion:: sql:: statement:: { calc_inline_constraints_from_columns, object_name_to_string} ;
33- use datafusion:: sql:: utils:: normalize_ident;
3433use datafusion_common:: { DFSchema , DFSchemaRef , SchemaReference , TableReference } ;
3534use datafusion_expr:: DropCatalogSchema ;
3635use sqlparser:: ast:: ObjectType ;
@@ -239,102 +238,72 @@ where
239238 }
240239
241240 fn show_objects_to_plan ( & self , parent : & ObjectName ) -> Result < LogicalPlan > {
241+ if !self . inner . has_table ( "information_schema" , "df_settings" ) {
242+ return plan_err ! ( "SHOW OBJECTS is not supported unless information_schema is enabled" ) ;
243+ }
242244 // Only support listing objects in schema for now
243245 match parent. 0 . len ( ) {
244246 2 => {
245- let ( catalog, schema) = ( parent. 0 [ 0 ] . value . clone ( ) , parent. 0 [ 1 ] . value . clone ( ) ) ;
247+ // let (catalog, schema) = (parent.0[0].value.clone(), parent.0[1].value.clone());
246248
247249 // Create query to list objects in schema
248250 let columns = [
249251 "table_catalog as 'database_name'" ,
250252 "table_schema as 'schema_name'" ,
251253 "table_name as 'name'" ,
252254 "case when table_type='BASE TABLE' then 'TABLE' else table_type end as 'kind'" ,
255+ "case when table_type='BASE TABLE' then 'Y' else 'N' end as 'is_iceberg'" ,
253256 "null as 'comment'" ,
254257 ]
255258 . join ( ", " ) ;
256259 // TODO: views?
257260 // 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- )
261+ let query = format ! ( "SELECT {columns} FROM information_schema.tables" ) ;
262+ self . parse_sql ( query. as_str ( ) )
270263 }
271264 _ => plan_err ! ( "Unsupported show objects: {:?}" , parent) ,
272265 }
273266 }
274267
275268 fn show_variable_to_plan ( & self , variable : & [ Ident ] ) -> Result < LogicalPlan > {
276- //println!("SHOW variable: {:?}", variable);
277269 if !self . inner . has_table ( "information_schema" , "df_settings" ) {
278270 return plan_err ! (
279271 "SHOW [VARIABLE] is not supported unless information_schema is enabled"
280272 ) ;
281273 }
282274
283- let verbose = variable
284- . last ( )
285- . is_some_and ( |s| normalize_ident ( s. to_owned ( ) ) == "verbose" ) ;
286- let mut variable_vec = variable. to_vec ( ) ;
287- let mut columns: String = "name, value" . to_owned ( ) ;
288-
289- // TODO: Fix how columns are selected. Vec instead of string
290- #[ allow( unused_assignments) ]
291- if verbose {
292- columns = format ! ( "{columns}, description" ) ;
293- variable_vec = variable_vec. split_at ( variable_vec. len ( ) - 1 ) . 0 . to_vec ( ) ;
294- }
295-
296- let query = if variable_vec. iter ( ) . any ( |ident| ident. value == "objects" ) {
297- columns = [
298- "table_catalog as 'database_name'" ,
299- "table_schema as 'schema_name'" ,
300- "table_name as 'name'" ,
301- "case when table_type='BASE TABLE' then 'TABLE' else table_type end as 'kind'" ,
302- "null as 'comment'" ,
303- ]
304- . join ( ", " ) ;
305- format ! ( "SELECT {columns} FROM information_schema.tables" )
275+ let variable = object_name_to_string ( & ObjectName ( variable. to_vec ( ) ) ) ;
276+ // let base_query = format!("SELECT {columns} FROM information_schema.df_settings");
277+ let base_query = "select schema_name as 'name' from information_schema.schemata" ;
278+ let query = if variable == "all" {
279+ // Add an ORDER BY so the output comes out in a consistent order
280+ format ! ( "{base_query} ORDER BY name" )
281+ } else if variable == "timezone" || variable == "time.zone" {
282+ // we could introduce alias in OptionDefinition if this string matching thing grows
283+ format ! ( "{base_query} WHERE name = 'datafusion.execution.time_zone'" )
306284 } else {
307- let variable = object_name_to_string ( & ObjectName ( variable_vec) ) ;
308- // let base_query = format!("SELECT {columns} FROM information_schema.df_settings");
309- let base_query = "select schema_name as 'name' from information_schema.schemata" ;
310- let query_res = if variable == "all" {
311- // Add an ORDER BY so the output comes out in a consistent order
312- format ! ( "{base_query} ORDER BY name" )
313- } else if variable == "timezone" || variable == "time.zone" {
314- // we could introduce alias in OptionDefinition if this string matching thing grows
315- format ! ( "{base_query} WHERE name = 'datafusion.execution.time_zone'" )
316- } else {
317- // These values are what are used to make the information_schema table, so we just
318- // check here, before actually planning or executing the query, if it would produce no
319- // results, and error preemptively if it would (for a better UX)
320- let is_valid_variable = self
321- . provider
322- . options ( )
323- . entries ( )
324- . iter ( )
325- . any ( |opt| opt. key == variable) ;
285+ // These values are what are used to make the information_schema table, so we just
286+ // check here, before actually planning or executing the query, if it would produce no
287+ // results, and error preemptively if it would (for a better UX)
288+ let is_valid_variable = self
289+ . provider
290+ . options ( )
291+ . entries ( )
292+ . iter ( )
293+ . any ( |opt| opt. key == variable) ;
326294
327- if is_valid_variable {
328- format ! ( "{base_query} WHERE name = '{variable}'" )
329- } else {
330- // skip where clause to return empty result
331- base_query. to_string ( )
332- }
333- } ;
334- query_res
295+ if is_valid_variable {
296+ format ! ( "{base_query} WHERE name = '{variable}'" )
297+ } else {
298+ // skip where clause to return empty result
299+ base_query. to_string ( )
300+ }
335301 } ;
302+ self . parse_sql ( query. as_str ( ) )
303+ }
336304
337- let mut statements = DFParser :: parse_sql ( query. as_str ( ) ) ?;
305+ fn parse_sql ( & self , sql : & str ) -> Result < LogicalPlan > {
306+ let mut statements = DFParser :: parse_sql ( sql) ?;
338307 statements. pop_front ( ) . map_or_else (
339308 || plan_err ! ( "Failed to parse SQL statement" ) ,
340309 |statement| {
0 commit comments