-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17502] [SQL] Fix Multiple Bugs in DDL Statements on Temporary Views #15054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
cc47c3e
855df61
61749b7
60371d8
6029a95
7c1a8e5
a01f6b3
333497a
5e40880
f305c4c
c662d2c
48ce44e
ee3096c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -913,7 +913,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| withTempView("show1a", "show2b") { | ||
| sql( | ||
| """ | ||
| |CREATE TEMPORARY TABLE show1a | ||
| |CREATE TEMPORARY VIEW show1a | ||
|
||
| |USING org.apache.spark.sql.sources.DDLScanSource | ||
| |OPTIONS ( | ||
| | From '1', | ||
|
|
@@ -924,7 +924,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| """.stripMargin) | ||
| sql( | ||
| """ | ||
| |CREATE TEMPORARY TABLE show2b | ||
| |CREATE TEMPORARY VIEW show2b | ||
| |USING org.apache.spark.sql.sources.DDLScanSource | ||
| |OPTIONS ( | ||
| | From '1', | ||
|
|
@@ -978,11 +978,11 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| Nil) | ||
| } | ||
|
|
||
| test("drop table - temporary table") { | ||
| test("drop table - temporary view") { | ||
| val catalog = spark.sessionState.catalog | ||
| sql( | ||
| """ | ||
| |CREATE TEMPORARY TABLE tab1 | ||
| |CREATE TEMPORARY VIEW tab1 | ||
| |USING org.apache.spark.sql.sources.DDLScanSource | ||
| |OPTIONS ( | ||
| | From '1', | ||
|
|
@@ -1605,7 +1605,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| } | ||
| } | ||
|
|
||
| test("truncate table - external table, temporary table, view (not allowed)") { | ||
| test("truncate table - external table, temporary view, view (not allowed)") { | ||
| import testImplicits._ | ||
| val path = Utils.createTempDir().getAbsolutePath | ||
| (1 to 10).map { i => (i, i) }.toDF("a", "b").createTempView("my_temp_tab") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,10 +82,70 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| } | ||
| } | ||
|
|
||
| test("error handling: insert/load/truncate table commands against a temp view") { | ||
| test("Issue exceptions for ALTER VIEW on the temporary view") { | ||
| val viewName = "testView" | ||
| withTempView(viewName) { | ||
| sql(s"CREATE TEMPORARY VIEW $viewName AS SELECT id FROM jt") | ||
| createTempView(viewName) | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'an')") | ||
| } | ||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER VIEW $viewName UNSET TBLPROPERTIES ('p')") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("Issue exceptions for ALTER TABLE on the temporary view") { | ||
| val viewName = "testView" | ||
| withTempView(viewName) { | ||
| createTempView(viewName) | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName SET SERDE 'whatever'") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName PARTITION (a=1, b=2) SET SERDE 'whatever'") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName SET SERDEPROPERTIES ('p' = 'an')") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName SET LOCATION '/path/to/your/lovely/heart'") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName PARTITION (a='4') SET LOCATION '/path/to/home'") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName ADD IF NOT EXISTS PARTITION (a='4', b='8')") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName DROP PARTITION (a='4', b='8')") | ||
| } | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ALTER TABLE $viewName PARTITION (a='4') RENAME TO PARTITION (a='5')") | ||
| } | ||
|
|
||
| val e = intercept[AnalysisException] { | ||
| sql(s"ALTER TABLE $viewName RECOVER PARTITIONS") | ||
| }.getMessage | ||
| assert(e.contains( | ||
| "Operation not allowed: ALTER TABLE RECOVER PARTITIONS on temporary tables: `testView`")) | ||
| } | ||
| } | ||
|
|
||
| test("Issue exceptions for other table DDL on the temporary view") { | ||
| val viewName = "testView" | ||
| withTempView(viewName) { | ||
| createTempView(viewName) | ||
|
|
||
| var e = intercept[AnalysisException] { | ||
| sql(s"INSERT INTO TABLE $viewName SELECT 1") | ||
| }.getMessage | ||
|
|
@@ -95,15 +155,38 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| e = intercept[AnalysisException] { | ||
| sql(s"""LOAD DATA LOCAL INPATH "$testData" INTO TABLE $viewName""") | ||
| }.getMessage | ||
| assert(e.contains(s"Target table in LOAD DATA cannot be temporary: `$viewName`")) | ||
| assert(e.contains(s"Operation not allowed: LOAD DATA on temporary tables: `$viewName`")) | ||
|
|
||
| e = intercept[AnalysisException] { | ||
| sql(s"TRUNCATE TABLE $viewName") | ||
| }.getMessage | ||
| assert(e.contains(s"Operation not allowed: TRUNCATE TABLE on temporary tables: `$viewName`")) | ||
|
|
||
| e = intercept[AnalysisException] { | ||
| sql(s"SHOW CREATE TABLE $viewName") | ||
| }.getMessage | ||
| assert(e.contains( | ||
| s"Operation not allowed: SHOW CREATE TABLE on temporary tables: `$viewName`")) | ||
|
|
||
| e = intercept[AnalysisException] { | ||
| sql(s"SHOW PARTITIONS $viewName") | ||
| }.getMessage | ||
| assert(e.contains(s"Operation not allowed: SHOW PARTITIONS on temporary tables: `$viewName`")) | ||
|
|
||
| intercept[NoSuchTableException] { | ||
| sql(s"ANALYZE TABLE $viewName COMPUTE STATISTICS") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def createTempView(viewName: String): Unit = { | ||
|
||
| sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW $viewName | ||
| |AS SELECT 1, 2, 3 | ||
| """.stripMargin) | ||
| } | ||
|
|
||
| test("error handling: insert/load/truncate table commands against a view") { | ||
| val viewName = "testView" | ||
| withView(viewName) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's follow the existing convention and call it
tableIdentWithDBThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Clean all the related naming issues.