This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 77c2180cf6 Remove DescribeTableStmt in parser in favour of existing
functionality from sqlparser-rs (#8703)
77c2180cf6 is described below
commit 77c2180cf6cb83a3e0aa6356b7017a2ed663d4f1
Author: Jeffrey <[email protected]>
AuthorDate: Tue Jan 2 04:30:20 2024 +1100
Remove DescribeTableStmt in parser in favour of existing functionality from
sqlparser-rs (#8703)
---
datafusion/core/src/execution/context/mod.rs | 3 ---
datafusion/sql/src/parser.rs | 22 ----------------------
datafusion/sql/src/statement.rs | 15 +++++++--------
3 files changed, 7 insertions(+), 33 deletions(-)
diff --git a/datafusion/core/src/execution/context/mod.rs
b/datafusion/core/src/execution/context/mod.rs
index 8916fa814a..c51f2d132a 100644
--- a/datafusion/core/src/execution/context/mod.rs
+++ b/datafusion/core/src/execution/context/mod.rs
@@ -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: _,
diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs
index 9c104ff18a..dbd72ec5eb 100644
--- a/datafusion/sql/src/parser.rs
+++ b/datafusion/sql/src/parser.rs
@@ -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
@@ -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
@@ -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}"),
}
@@ -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
@@ -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
diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs
index a365d23f43..b96553ffbf 100644
--- a/datafusion/sql/src/statement.rs
+++ b/datafusion/sql/src/statement.rs
@@ -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,
@@ -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,
@@ -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,
@@ -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)?;