MCPcopy Create free account
hub / github.com/apache/datafusion / show_columns_to_plan

Method show_columns_to_plan

datafusion/sql/src/statement.rs:2514–2550  ·  view source on GitHub ↗
(
        &self,
        extended: bool,
        full: bool,
        sql_table_name: ObjectName,
    )

Source from the content-addressed store, hash-verified

2512 }
2513
2514 fn show_columns_to_plan(
2515 &self,
2516 extended: bool,
2517 full: bool,
2518 sql_table_name: ObjectName,
2519 ) -> Result<LogicalPlan> {
2520 // Figure out the where clause
2521 let where_clause = object_name_to_qualifier(
2522 &sql_table_name,
2523 self.options.enable_ident_normalization,
2524 )?;
2525
2526 if !self.has_table("information_schema", "columns") {
2527 return plan_err!(
2528 "SHOW COLUMNS is not supported unless information_schema is enabled"
2529 );
2530 }
2531
2532 // Do a table lookup to verify the table exists
2533 let table_ref = self.object_name_to_table_reference(sql_table_name)?;
2534 let _ = self.context_provider.get_table_source(table_ref)?;
2535
2536 // Treat both FULL and EXTENDED as the same
2537 let select_list = if full || extended {
2538 "*"
2539 } else {
2540 "table_catalog, table_schema, table_name, column_name, data_type, is_nullable"
2541 };
2542
2543 let query = format!(
2544 "SELECT {select_list} FROM information_schema.columns WHERE {where_clause}"
2545 );
2546
2547 let mut rewrite = DFParser::parse_sql(&query)?;
2548 assert_eq!(rewrite.len(), 1);
2549 self.statement_to_plan(rewrite.pop_front().unwrap()) // length of rewrite is 1
2550 }
2551
2552 /// Rewrite `SHOW FUNCTIONS` to another SQL query
2553 /// The query is based on the `information_schema.routines` and `information_schema.parameters` tables

Calls 6

object_name_to_qualifierFunction · 0.85
has_tableMethod · 0.80
pop_frontMethod · 0.80
get_table_sourceMethod · 0.45
statement_to_planMethod · 0.45

Tested by

no test coverage detected