Skip to content
Merged
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
table_name,
..
} => self.describe_table_to_plan(table_name),
Statement::Explain {
describe_alias: DescribeAlias::Describe | DescribeAlias::Desc, // only parse 'DESCRIBE statement' or 'DESC statement' and not 'EXPLAIN statement'
statement,
..
} => match *statement {
Statement::Query(query) => self.describe_query_to_plan(*query),
_ => Err(DataFusionError::NotImplemented(format!(
Comment thread
djanderson marked this conversation as resolved.
Outdated
"Unsupported statement type for DESCRIBE: {statement:?}",
))),
},
Statement::Explain {
verbose,
statement,
Expand Down Expand Up @@ -1396,6 +1406,19 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
}))
}

fn describe_query_to_plan(&self, query: Query) -> Result<LogicalPlan> {
let plan = self.query_to_plan(query, &mut PlannerContext::new())?;

let schema = Arc::new(plan.schema().as_arrow().clone());

let output_schema = DFSchema::try_from(LogicalPlan::describe_schema()).unwrap();

Ok(LogicalPlan::DescribeTable(DescribeTable {
schema,
output_schema: Arc::new(output_schema),
}))
}

fn copy_to_plan(&self, statement: CopyToStatement) -> Result<LogicalPlan> {
// Determine if source is table or query and handle accordingly
let copy_source = statement.source;
Expand Down