-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19539][SQL] Block duplicate temp table during creation #16878
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
0afe3cb
290fa15
4a3a06a
f7253c5
6683d8c
3a989cf
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 |
|---|---|---|
|
|
@@ -903,7 +903,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', | ||
|
|
@@ -914,7 +914,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', | ||
|
|
@@ -958,11 +958,11 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| Nil) | ||
| } | ||
|
|
||
| test("drop table - temporary table") { | ||
| test("drop view - 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', | ||
|
|
@@ -971,7 +971,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| |) | ||
| """.stripMargin) | ||
| assert(catalog.listTables("default") == Seq(TableIdentifier("tab1"))) | ||
| sql("DROP TABLE tab1") | ||
| sql("DROP view tab1") | ||
|
||
| assert(catalog.listTables("default") == Nil) | ||
| } | ||
|
|
||
|
|
@@ -1690,6 +1690,16 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| } | ||
| } | ||
|
|
||
| test("block creating duplicate temp table") { | ||
| withView("t_temp") { | ||
| sql("CREATE TEMPORARY VIEW t_temp AS SELECT 1, 2") | ||
| val e = intercept[TempTableAlreadyExistsException] { | ||
| sql("CREATE TEMPORARY TABLE t_temp (c3 int, c4 string) USING JSON") | ||
| }.getMessage | ||
| assert(e.contains("Temporary table 't_temp' already exists")) | ||
| } | ||
| } | ||
|
|
||
| test("truncate table - external table, temporary table, view (not allowed)") { | ||
| import testImplicits._ | ||
| withTempPath { tempDir => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,15 +187,17 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { | |
|
|
||
| test("test different encoding") { | ||
| // scalastyle:off | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY TABLE carsTable USING csv | ||
| withView("carsTable") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW carsTable USING csv | ||
|
||
| |OPTIONS (path "${testFile(carsFile8859)}", header "true", | ||
| |charset "iso-8859-1", delimiter "þ") | ||
| """.stripMargin.replaceAll("\n", " ")) | ||
| // scalastyle:on | ||
|
|
||
| verifyCars(spark.table("carsTable"), withHeader = true) | ||
| verifyCars(spark.table("carsTable"), withHeader = true) | ||
| } | ||
| } | ||
|
|
||
| test("test aliases sep and encoding for delimiter and charset") { | ||
|
|
@@ -213,27 +215,31 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { | |
| } | ||
|
|
||
| test("DDL test with tab separated file") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY TABLE carsTable USING csv | ||
| withView("carsTable") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW carsTable USING csv | ||
|
||
| |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") | ||
| """.stripMargin.replaceAll("\n", " ")) | ||
|
|
||
| verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) | ||
| verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) | ||
| } | ||
| } | ||
|
|
||
| test("DDL test parsing decimal type") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY TABLE carsTable | ||
| withView("carsTable") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW carsTable | ||
|
||
| |(yearMade double, makeName string, modelName string, priceTag decimal, | ||
| | comments string, grp string) | ||
| |USING csv | ||
| |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") | ||
| """.stripMargin.replaceAll("\n", " ")) | ||
|
|
||
| assert( | ||
| spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) | ||
| assert( | ||
| spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) | ||
| } | ||
| } | ||
|
|
||
| test("test for DROPMALFORMED parsing mode") { | ||
|
|
@@ -300,28 +306,34 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { | |
| } | ||
|
|
||
| test("DDL test with empty file") { | ||
| spark.sql(s""" | ||
| |CREATE TEMPORARY TABLE carsTable | ||
| withView("carsTable") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW carsTable | ||
|
||
| |(yearMade double, makeName string, modelName string, comments string, grp string) | ||
| |USING csv | ||
| |OPTIONS (path "${testFile(emptyFile)}", header "false") | ||
| """.stripMargin.replaceAll("\n", " ")) | ||
|
|
||
| assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) | ||
| assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) | ||
| } | ||
| } | ||
|
|
||
| test("DDL test with schema") { | ||
| spark.sql(s""" | ||
| |CREATE TEMPORARY TABLE carsTable | ||
| withView("carsTable") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TEMPORARY VIEW carsTable | ||
|
||
| |(yearMade double, makeName string, modelName string, comments string, blank string) | ||
| |USING csv | ||
| |OPTIONS (path "${testFile(carsFile)}", header "true") | ||
| """.stripMargin.replaceAll("\n", " ")) | ||
|
|
||
| val cars = spark.table("carsTable") | ||
| verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) | ||
| assert( | ||
| cars.schema.fieldNames === Array("yearMade", "makeName", "modelName", "comments", "blank")) | ||
| val cars = spark.table("carsTable") | ||
| verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) | ||
| assert( | ||
| cars.schema.fieldNames === Array("yearMade", "makeName", "modelName", "comments", "blank")) | ||
| } | ||
| } | ||
|
|
||
| test("save csv") { | ||
|
|
||
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.
can you check when did we forbid this? maybe it's time to fully remove the support
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.
@cloud-fan Thanks for reviewing! I found that this deprecation was added by your PR #14482 back on 8/5/2016. Do you think it is the right time to remove
CREATE TEMPORARY TABLE...completely?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.
no, it should be earlier: https://github.com/apache/spark/pull/14482/files#diff-7253a38df7e111ecf6b1ef71feba383bL425
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.
Are we referring to the same PR? I found the change here https://github.com/apache/spark/pull/14482/files#diff-1bb4f7bd5a2656f48bcd3c857167a11bR362, where this WARN message is added in
SparkSQLParser.scalaThere 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.
I mean it was moved from other places, so this warning should have been added earlier.
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.
I see. sorry. I misunderstood. Let me check further.
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.
#13414 deprecated this. Merged on Jun 7th, 2016.
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.
it was merged to 2.0, let's keep it