Skip to content

Commit 234accf

Browse files
committed
Update handling of SHOW COLUMNs/SHOW DATABASE
1 parent ba0ae2c commit 234accf

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

datafusion/sql/src/statement.rs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ use datafusion_expr::{
5454
TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
5555
Volatility, WriteOp,
5656
};
57-
use sqlparser::ast::{self, ShowStatementOptions, SqliteOnConflict};
57+
use sqlparser::ast::{self, ShowStatementIn, ShowStatementOptions, SqliteOnConflict};
5858
use sqlparser::ast::{
5959
Assignment, AssignmentTarget, ColumnDef, CreateIndex, CreateTable,
6060
CreateTableOptions, Delete, DescribeAlias, Expr as SQLExpr, FromTable, Ident, Insert,
6161
ObjectName, ObjectType, OneOrManyWithParens, Query, SchemaName, SetExpr,
62-
ShowCreateObject, ShowStatementFilter, Statement, TableConstraint, TableFactor,
63-
TableWithJoins, TransactionMode, UnaryOperator, Value,
62+
ShowCreateObject, Statement, TableConstraint, TableFactor, TableWithJoins,
63+
TransactionMode, UnaryOperator, Value,
6464
};
6565
use sqlparser::parser::ParserError::ParserError;
6666

@@ -735,12 +735,49 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
735735
Statement::ShowColumns {
736736
extended,
737737
full,
738-
//table_name,
739-
//filter,
740-
show_options: _,
738+
show_options,
741739
} => {
742-
todo!("Update show columns / fix for new syntax");
743-
//self.show_columns_to_plan(extended, full, table_name, filter)
740+
let ShowStatementOptions {
741+
show_in,
742+
starts_with,
743+
limit,
744+
limit_from,
745+
filter_position,
746+
} = show_options;
747+
if starts_with.is_some() {
748+
return not_impl_err!("SHOW COLUMNS LIKE not supported")?;
749+
}
750+
if limit.is_some() {
751+
return not_impl_err!("SHOW COLUMNS LIMIT not supported")?;
752+
}
753+
if limit_from.is_some() {
754+
return not_impl_err!("SHOW COLUMNS LIMIT FROM not supported")?;
755+
}
756+
if filter_position.is_some() {
757+
return not_impl_err!("SHOW COLUMNS FILTER not supported")?;
758+
}
759+
if filter_position.is_some() {
760+
return not_impl_err!("SHOW COLUMNS FILTER not supported")?;
761+
}
762+
let Some(ShowStatementIn {
763+
// specifies if the syntax was `SHOW COLUMNS IN` or `SHOW
764+
// COLUMNS FROM` which is not different in DataFusion
765+
clause: _,
766+
parent_type,
767+
parent_name,
768+
}) = show_in
769+
else {
770+
return plan_err!("SHOW COLUMNS requires a table name");
771+
};
772+
773+
if let Some(parent_type) = parent_type {
774+
return not_impl_err!("SHOW COLUMNS IN {parent_type} not supported");
775+
}
776+
let Some(table_name) = parent_name else {
777+
return plan_err!("SHOW COLUMNS requires a table name");
778+
};
779+
780+
self.show_columns_to_plan(extended, full, table_name)
744781
}
745782

746783
Statement::Insert(Insert {
@@ -1878,17 +1915,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
18781915
extended: bool,
18791916
full: bool,
18801917
sql_table_name: ObjectName,
1881-
filter: Option<ShowStatementFilter>,
18821918
) -> Result<LogicalPlan> {
1883-
if filter.is_some() {
1884-
return plan_err!("SHOW COLUMNS with WHERE or LIKE is not supported");
1885-
}
1886-
1887-
if !self.has_table("information_schema", "columns") {
1888-
return plan_err!(
1889-
"SHOW COLUMNS is not supported unless information_schema is enabled"
1890-
);
1891-
}
18921919
// Figure out the where clause
18931920
let where_clause = object_name_to_qualifier(
18941921
&sql_table_name,

0 commit comments

Comments
 (0)