-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-19539][SQL] Block duplicate temp table during creation #16878
Conversation
@gatorsmile @cloud-fan Thanks! |
Test build #72670 has finished for PR 16878 at commit
|
@@ -425,7 +425,9 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { | |||
|
|||
logWarning(s"CREATE TEMPORARY TABLE ... USING ... is deprecated, please use " + |
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.scala
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 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
|CREATE TEMPORARY TABLE carsTable USING csv | ||
|OPTIONS (path "${testFile(carsFile8859)}", header "true", | ||
|charset "iso-8859-1", delimiter "þ") | ||
""".stripMargin.replaceAll("\n", " ")) | ||
""".stripMargin. | ||
replaceAll("\n", " ")) |
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 can be put in the previous line
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.
yes. thanks!
|
||
verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) | ||
)) |
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 can be put in the previous line
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.
yes. Thanks!
s""" | ||
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY TABLE carsTable USING 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.
as you are fixing this test suite, can you replace all CREATE TEMPORARY TABLE
to VIEW
?
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.
Will do. Thanks!
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 there are test cases that are related to ALTER TABLE for the temp table, should we keep such test cases for a while?
@@ -425,7 +425,9 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { | |||
|
|||
logWarning(s"CREATE TEMPORARY TABLE ... USING ... is deprecated, please use " + | |||
"CREATE TEMPORARY VIEW ... USING ... instead") | |||
CreateTempViewUsing(table, schema, replace = true, global = false, provider, options) | |||
// Since we don't support IF NOT EXISTS for temp table, we should not allow | |||
// replacing existing temp table, that may accidentally remove a temp view in use. |
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.
Just got your points... How about update the description to
Unlike CREATE TEMPORARY VIEW USING, CREATE TEMPORARY TABLE USING does not support IF NOT EXISTS. Users are not allowed to replace the existing temp table.
Thanks!
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.
OK. Good point. Thanks!
val e = intercept[TempTableAlreadyExistsException] { | ||
sql("CREATE TEMPORARY TABLE t_temp (c3 int, c4 string) USING JSON") | ||
}.getMessage | ||
assert(e.contains("already exists")) |
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.
Please capture the whole error message.
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.
OK.
133bd99
to
f7253c5
Compare
Test build #72800 has finished for PR 16878 at commit
|
@@ -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") |
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.
nit: upper case "view"
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY VIEW carsTable USING 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.
the indention is wrong
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY VIEW carsTable USING 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.
the indention is wrong
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY VIEW carsTable |
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.
the indention is wrong
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY VIEW carsTable |
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.
the indention is wrong
withView("carsTable") { | ||
spark.sql( | ||
s""" | ||
|CREATE TEMPORARY VIEW carsTable |
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.
the indention is wrong
LGTM, pending jenkins, thanks for working on it! |
Test build #72834 has finished for PR 16878 at commit
|
Test build #72837 has finished for PR 16878 at commit
|
Thanks! Merging to master. |
## What changes were proposed in this pull request? Current `CREATE TEMPORARY TABLE ... ` is deprecated and recommend users to use `CREATE TEMPORARY VIEW ...` And it does not support `IF NOT EXISTS `clause. However, if there is an existing temporary view defined, it is possible to unintentionally replace this existing view by issuing `CREATE TEMPORARY TABLE ...` with the same table/view name. This PR is to disallow `CREATE TEMPORARY TABLE ...` with an existing view name. Under the cover, `CREATE TEMPORARY TABLE ...` will be changed to create temporary view, however, passing in a flag `replace=false`, instead of currently `true`. So when creating temporary view under the cover, if there is existing view with the same name, the operation will be blocked. ## How was this patch tested? New unit test case is added and updated some existing test cases to adapt the new behavior Author: Xin Wu <xinwu@us.ibm.com> Closes apache#16878 from xwu0226/block_duplicate_temp_table.
What changes were proposed in this pull request?
Current
CREATE TEMPORARY TABLE ...
is deprecated and recommend users to useCREATE TEMPORARY VIEW ...
And it does not supportIF NOT EXISTS
clause. However, if there is an existing temporary view defined, it is possible to unintentionally replace this existing view by issuingCREATE TEMPORARY TABLE ...
with the same table/view name.This PR is to disallow
CREATE TEMPORARY TABLE ...
with an existing view name.Under the cover,
CREATE TEMPORARY TABLE ...
will be changed to create temporary view, however, passing in a flagreplace=false
, instead of currentlytrue
. So when creating temporary view under the cover, if there is existing view with the same name, the operation will be blocked.How was this patch tested?
New unit test case is added and updated some existing test cases to adapt the new behavior