Skip to content

Commit

Permalink
Remove DescribeTableStmt in parser in favour of existing functionalit…
Browse files Browse the repository at this point in the history
…y from sqlparser-rs (#8703)
  • Loading branch information
Jefffrey authored Jan 1, 2024
1 parent 4dcfd7d commit 77c2180
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
3 changes: 0 additions & 3 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,9 +1621,6 @@ impl SessionState {
.0
.insert(ObjectName(vec![Ident::from(table.name.as_str())]));
}
DFStatement::DescribeTableStmt(table) => {
visitor.insert(&table.table_name)
}
DFStatement::CopyTo(CopyToStatement {
source,
target: _,
Expand Down
22 changes: 0 additions & 22 deletions datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,6 @@ impl fmt::Display for CreateExternalTable {
}
}

/// DataFusion extension DDL for `DESCRIBE TABLE`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DescribeTableStmt {
/// Table name
pub table_name: ObjectName,
}

/// DataFusion SQL Statement.
///
/// This can either be a [`Statement`] from [`sqlparser`] from a
Expand All @@ -233,8 +226,6 @@ pub enum Statement {
Statement(Box<SQLStatement>),
/// Extension: `CREATE EXTERNAL TABLE`
CreateExternalTable(CreateExternalTable),
/// Extension: `DESCRIBE TABLE`
DescribeTableStmt(DescribeTableStmt),
/// Extension: `COPY TO`
CopyTo(CopyToStatement),
/// EXPLAIN for extensions
Expand All @@ -246,7 +237,6 @@ impl fmt::Display for Statement {
match self {
Statement::Statement(stmt) => write!(f, "{stmt}"),
Statement::CreateExternalTable(stmt) => write!(f, "{stmt}"),
Statement::DescribeTableStmt(_) => write!(f, "DESCRIBE TABLE ..."),
Statement::CopyTo(stmt) => write!(f, "{stmt}"),
Statement::Explain(stmt) => write!(f, "{stmt}"),
}
Expand Down Expand Up @@ -345,10 +335,6 @@ impl<'a> DFParser<'a> {
self.parser.next_token(); // COPY
self.parse_copy()
}
Keyword::DESCRIBE => {
self.parser.next_token(); // DESCRIBE
self.parse_describe()
}
Keyword::EXPLAIN => {
// (TODO parse all supported statements)
self.parser.next_token(); // EXPLAIN
Expand All @@ -371,14 +357,6 @@ impl<'a> DFParser<'a> {
}
}

/// Parse a SQL `DESCRIBE` statement
pub fn parse_describe(&mut self) -> Result<Statement, ParserError> {
let table_name = self.parser.parse_object_name()?;
Ok(Statement::DescribeTableStmt(DescribeTableStmt {
table_name,
}))
}

/// Parse a SQL `COPY TO` statement
pub fn parse_copy(&mut self) -> Result<Statement, ParserError> {
// parse as a query
Expand Down
15 changes: 7 additions & 8 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::Arc;

use crate::parser::{
CopyToSource, CopyToStatement, CreateExternalTable, DFParser, DescribeTableStmt,
ExplainStatement, LexOrdering, Statement as DFStatement,
CopyToSource, CopyToStatement, CreateExternalTable, DFParser, ExplainStatement,
LexOrdering, Statement as DFStatement,
};
use crate::planner::{
object_name_to_qualifier, ContextProvider, PlannerContext, SqlToRel,
Expand Down Expand Up @@ -136,7 +136,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
match statement {
DFStatement::CreateExternalTable(s) => self.external_table_to_plan(s),
DFStatement::Statement(s) => self.sql_statement_to_plan(*s),
DFStatement::DescribeTableStmt(s) => self.describe_table_to_plan(s),
DFStatement::CopyTo(s) => self.copy_to_plan(s),
DFStatement::Explain(ExplainStatement {
verbose,
Expand Down Expand Up @@ -170,6 +169,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
) -> Result<LogicalPlan> {
let sql = Some(statement.to_string());
match statement {
Statement::ExplainTable {
describe_alias: true, // only parse 'DESCRIBE table_name' and not 'EXPLAIN table_name'
table_name,
} => self.describe_table_to_plan(table_name),
Statement::Explain {
verbose,
statement,
Expand Down Expand Up @@ -635,11 +638,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

fn describe_table_to_plan(
&self,
statement: DescribeTableStmt,
) -> Result<LogicalPlan> {
let DescribeTableStmt { table_name } = statement;
fn describe_table_to_plan(&self, table_name: ObjectName) -> Result<LogicalPlan> {
let table_ref = self.object_name_to_table_reference(table_name)?;

let table_source = self.context_provider.get_table_source(table_ref)?;
Expand Down

0 comments on commit 77c2180

Please sign in to comment.