@@ -54,13 +54,13 @@ use datafusion_expr::{
5454 TransactionConclusion , TransactionEnd , TransactionIsolationLevel , TransactionStart ,
5555 Volatility , WriteOp ,
5656} ;
57- use sqlparser:: ast:: { self , SqliteOnConflict } ;
57+ use sqlparser:: ast:: { self , ShowStatementIn , ShowStatementOptions , SqliteOnConflict } ;
5858use 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} ;
6565use sqlparser:: parser:: ParserError :: ParserError ;
6666
@@ -685,19 +685,99 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
685685 Statement :: ShowTables {
686686 extended,
687687 full,
688- db_name,
689- filter,
690- // SHOW TABLES IN/FROM are equivalent, this field specifies which the user
691- // specified, but it doesn't affect the plan so ignore the field
692- clause : _,
693- } => self . show_tables_to_plan ( extended, full, db_name, filter) ,
688+ terse,
689+ history,
690+ external,
691+ show_options,
692+ } => {
693+ // We only support the basic "SHOW TABLES"
694+ // https://github.com/apache/datafusion/issues/3188
695+ if extended {
696+ return not_impl_err ! ( "SHOW TABLES EXTENDED not supported" ) ?;
697+ }
698+ if full {
699+ return not_impl_err ! ( "SHOW FULL TABLES not supported" ) ?;
700+ }
701+ if terse {
702+ return not_impl_err ! ( "SHOW TERSE TABLES not supported" ) ?;
703+ }
704+ if history {
705+ return not_impl_err ! ( "SHOW TABLES HISTORY not supported" ) ?;
706+ }
707+ if external {
708+ return not_impl_err ! ( "SHOW EXTERNAL TABLES not supported" ) ?;
709+ }
710+ let ShowStatementOptions {
711+ show_in,
712+ starts_with,
713+ limit,
714+ limit_from,
715+ filter_position,
716+ } = show_options;
717+ if show_in. is_some ( ) {
718+ return not_impl_err ! ( "SHOW TABLES IN not supported" ) ?;
719+ }
720+ if starts_with. is_some ( ) {
721+ return not_impl_err ! ( "SHOW TABLES LIKE not supported" ) ?;
722+ }
723+ if limit. is_some ( ) {
724+ return not_impl_err ! ( "SHOW TABLES LIMIT not supported" ) ?;
725+ }
726+ if limit_from. is_some ( ) {
727+ return not_impl_err ! ( "SHOW TABLES LIMIT FROM not supported" ) ?;
728+ }
729+ if filter_position. is_some ( ) {
730+ return not_impl_err ! ( "SHOW TABLES FILTER not supported" ) ?;
731+ }
732+ self . show_tables_to_plan ( )
733+ }
694734
695735 Statement :: ShowColumns {
696736 extended,
697737 full,
698- table_name,
699- filter,
700- } => self . show_columns_to_plan ( extended, full, table_name, filter) ,
738+ show_options,
739+ } => {
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 ! (
758+ "SHOW COLUMNS with WHERE or LIKE is not supported"
759+ ) ?;
760+ }
761+ let Some ( ShowStatementIn {
762+ // specifies if the syntax was `SHOW COLUMNS IN` or `SHOW
763+ // COLUMNS FROM` which is not different in DataFusion
764+ clause : _,
765+ parent_type,
766+ parent_name,
767+ } ) = show_in
768+ else {
769+ return plan_err ! ( "SHOW COLUMNS requires a table name" ) ;
770+ } ;
771+
772+ if let Some ( parent_type) = parent_type {
773+ return not_impl_err ! ( "SHOW COLUMNS IN {parent_type} not supported" ) ;
774+ }
775+ let Some ( table_name) = parent_name else {
776+ return plan_err ! ( "SHOW COLUMNS requires a table name" ) ;
777+ } ;
778+
779+ self . show_columns_to_plan ( extended, full, table_name)
780+ }
701781
702782 Statement :: Insert ( Insert {
703783 or,
@@ -766,10 +846,14 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
766846 from,
767847 selection,
768848 returning,
849+ or,
769850 } => {
770851 if returning. is_some ( ) {
771852 plan_err ! ( "Update-returning clause not yet supported" ) ?;
772853 }
854+ if or. is_some ( ) {
855+ plan_err ! ( "ON conflict not supported" ) ?;
856+ }
773857 self . update_to_plan ( table, assignments, from, selection)
774858 }
775859
@@ -1065,24 +1149,12 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10651149 }
10661150
10671151 /// Generate a logical plan from a "SHOW TABLES" query
1068- fn show_tables_to_plan (
1069- & self ,
1070- extended : bool ,
1071- full : bool ,
1072- db_name : Option < Ident > ,
1073- filter : Option < ShowStatementFilter > ,
1074- ) -> Result < LogicalPlan > {
1152+ fn show_tables_to_plan ( & self ) -> Result < LogicalPlan > {
10751153 if self . has_table ( "information_schema" , "tables" ) {
1076- // We only support the basic "SHOW TABLES"
1077- // https://github.com/apache/datafusion/issues/3188
1078- if db_name. is_some ( ) || filter. is_some ( ) || full || extended {
1079- plan_err ! ( "Unsupported parameters to SHOW TABLES" )
1080- } else {
1081- let query = "SELECT * FROM information_schema.tables;" ;
1082- let mut rewrite = DFParser :: parse_sql ( query) ?;
1083- assert_eq ! ( rewrite. len( ) , 1 ) ;
1084- self . statement_to_plan ( rewrite. pop_front ( ) . unwrap ( ) ) // length of rewrite is 1
1085- }
1154+ let query = "SELECT * FROM information_schema.tables;" ;
1155+ let mut rewrite = DFParser :: parse_sql ( query) ?;
1156+ assert_eq ! ( rewrite. len( ) , 1 ) ;
1157+ self . statement_to_plan ( rewrite. pop_front ( ) . unwrap ( ) ) // length of rewrite is 1
10861158 } else {
10871159 plan_err ! ( "SHOW TABLES is not supported unless information_schema is enabled" )
10881160 }
@@ -1842,22 +1914,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
18421914 extended : bool ,
18431915 full : bool ,
18441916 sql_table_name : ObjectName ,
1845- filter : Option < ShowStatementFilter > ,
18461917 ) -> Result < LogicalPlan > {
1847- if filter. is_some ( ) {
1848- return plan_err ! ( "SHOW COLUMNS with WHERE or LIKE is not supported" ) ;
1849- }
1918+ // Figure out the where clause
1919+ let where_clause = object_name_to_qualifier (
1920+ & sql_table_name,
1921+ self . options . enable_ident_normalization ,
1922+ ) ;
18501923
18511924 if !self . has_table ( "information_schema" , "columns" ) {
18521925 return plan_err ! (
18531926 "SHOW COLUMNS is not supported unless information_schema is enabled"
18541927 ) ;
18551928 }
1856- // Figure out the where clause
1857- let where_clause = object_name_to_qualifier (
1858- & sql_table_name,
1859- self . options . enable_ident_normalization ,
1860- ) ;
18611929
18621930 // Do a table lookup to verify the table exists
18631931 let table_ref = self . object_name_to_table_reference ( sql_table_name) ?;
0 commit comments