Skip to content

Commit a471c7f

Browse files
sureshthalamatihvanhovell
authored andcommitted
[SPARK-14133][SQL] Throws exception for unsupported create/drop/alter index , and lock/unlock operations.
## What changes were proposed in this pull request? This PR throws Unsupported Operation exception for create index, drop index, alter index , lock table , lock database, unlock table, and unlock database operations that are not supported in Spark SQL. Currently these operations are executed executed by Hive. Error: spark-sql> drop index my_index on my_table; Error in query: Unsupported operation: drop index(line 1, pos 0) ## How was this patch tested? Added test cases to HiveQuerySuite yhuai hvanhovell andrewor14 Author: sureshthalamati <[email protected]> Closes #12069 from sureshthalamati/unsupported_ddl_spark-14133.
1 parent 0b04f8f commit a471c7f

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ hiveNativeCommands
146146
| ROLLBACK WORK?
147147
| SHOW PARTITIONS tableIdentifier partitionSpec?
148148
| DFS .*?
149-
| (CREATE | ALTER | DROP | SHOW | DESC | DESCRIBE | LOCK | UNLOCK | MSCK | LOAD) .*?
149+
| (CREATE | ALTER | DROP | SHOW | DESC | DESCRIBE | MSCK | LOAD) .*?
150150
;
151151

152152
unsupportedHiveNativeCommands
@@ -166,6 +166,13 @@ unsupportedHiveNativeCommands
166166
| kw1=SHOW kw2=TRANSACTIONS
167167
| kw1=SHOW kw2=INDEXES
168168
| kw1=SHOW kw2=LOCKS
169+
| kw1=CREATE kw2=INDEX
170+
| kw1=DROP kw2=INDEX
171+
| kw1=ALTER kw2=INDEX
172+
| kw1=LOCK kw2=TABLE
173+
| kw1=LOCK kw2=DATABASE
174+
| kw1=UNLOCK kw2=TABLE
175+
| kw1=UNLOCK kw2=DATABASE
169176
;
170177

171178
createTableHeader
@@ -640,7 +647,7 @@ nonReserved
640647
| INPUTDRIVER | OUTPUTDRIVER | DBPROPERTIES | DFS | TRUNCATE | METADATA | REPLICATION | COMPUTE
641648
| STATISTICS | ANALYZE | PARTITIONED | EXTERNAL | DEFINED | RECORDWRITER
642649
| REVOKE | GRANT | LOCK | UNLOCK | MSCK | EXPORT | IMPORT | LOAD | VALUES | COMMENT | ROLE
643-
| ROLES | COMPACTIONS | PRINCIPALS | TRANSACTIONS | INDEXES | LOCKS | OPTION
650+
| ROLES | COMPACTIONS | PRINCIPALS | TRANSACTIONS | INDEX | INDEXES | LOCKS | OPTION
644651
;
645652

646653
SELECT: 'SELECT';
@@ -861,6 +868,7 @@ ROLES: 'ROLES';
861868
COMPACTIONS: 'COMPACTIONS';
862869
PRINCIPALS: 'PRINCIPALS';
863870
TRANSACTIONS: 'TRANSACTIONS';
871+
INDEX: 'INDEX';
864872
INDEXES: 'INDEXES';
865873
LOCKS: 'LOCKS';
866874
OPTION: 'OPTION';

sql/hive/compatibility/src/test/scala/org/apache/spark/sql/hive/execution/HiveCompatibilitySuite.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,12 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
352352
"show_create_table_index",
353353
"show_create_table_partitioned",
354354
"show_create_table_serde",
355-
"show_create_table_view"
355+
"show_create_table_view",
356+
357+
// Index commands are not supported
358+
"drop_index",
359+
"drop_index_removes_partition_dirs",
360+
"alter_index"
356361
)
357362

358363
/**
@@ -369,7 +374,6 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
369374
"alter3",
370375
"alter4",
371376
"alter5",
372-
"alter_index",
373377
"alter_merge_2",
374378
"alter_partition_format_loc",
375379
"alter_partition_with_whitelist",
@@ -496,8 +500,6 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
496500
"distinct_stats",
497501
"drop_database_removes_partition_dirs",
498502
"drop_function",
499-
"drop_index",
500-
"drop_index_removes_partition_dirs",
501503
"drop_multi_partitions",
502504
"drop_partitions_filter",
503505
"drop_partitions_filter2",

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,21 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter {
12801280
assertUnsupportedFeature { sql("SHOW LOCKS my_table") }
12811281
}
12821282

1283+
test("lock/unlock table and database commands are not supported") {
1284+
assertUnsupportedFeature { sql("LOCK TABLE my_table SHARED") }
1285+
assertUnsupportedFeature { sql("UNLOCK TABLE my_table") }
1286+
assertUnsupportedFeature { sql("LOCK DATABASE my_db SHARED") }
1287+
assertUnsupportedFeature { sql("UNLOCK DATABASE my_db") }
1288+
}
1289+
1290+
test("create/drop/alter index commands are not supported") {
1291+
assertUnsupportedFeature {
1292+
sql("CREATE INDEX my_index ON TABLE my_table(a) as 'COMPACT' WITH DEFERRED REBUILD")}
1293+
assertUnsupportedFeature { sql("DROP INDEX my_index ON my_table") }
1294+
assertUnsupportedFeature { sql("ALTER INDEX my_index ON my_table REBUILD")}
1295+
assertUnsupportedFeature {
1296+
sql("ALTER INDEX my_index ON my_table set IDXPROPERTIES (\"prop1\"=\"val1_new\")")}
1297+
}
12831298
}
12841299

12851300
// for SPARK-2180 test

0 commit comments

Comments
 (0)