Skip to content

Conversation

@xwu0226
Copy link
Contributor

@xwu0226 xwu0226 commented Feb 10, 2017

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

@xwu0226
Copy link
Contributor Author

xwu0226 commented Feb 10, 2017

@gatorsmile @cloud-fan Thanks!

@SparkQA
Copy link

SparkQA commented Feb 10, 2017

Test build #72670 has finished for PR 16878 at commit 133bd99.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. thanks!

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Thanks!

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Thanks!

Copy link
Contributor Author

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?

Copy link
Member

@gatorsmile gatorsmile Feb 12, 2017

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Good point. Thanks!

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@xwu0226 xwu0226 force-pushed the block_duplicate_temp_table branch from 133bd99 to f7253c5 Compare February 13, 2017 05:32
@SparkQA
Copy link

SparkQA commented Feb 13, 2017

Test build #72800 has finished for PR 16878 at commit f7253c5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

""".stripMargin)
assert(catalog.listTables("default") == Seq(TableIdentifier("tab1")))
sql("DROP TABLE tab1")
sql("DROP view tab1")
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indention is wrong

@cloud-fan
Copy link
Contributor

LGTM, pending jenkins, thanks for working on it!

@SparkQA
Copy link

SparkQA commented Feb 14, 2017

Test build #72834 has finished for PR 16878 at commit 6683d8c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 14, 2017

Test build #72837 has finished for PR 16878 at commit 3a989cf.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

Thanks! Merging to master.

@asfgit asfgit closed this in 1ab9731 Feb 14, 2017
cmonkey pushed a commit to cmonkey/spark that referenced this pull request Feb 15, 2017
## 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 <[email protected]>

Closes apache#16878 from xwu0226/block_duplicate_temp_table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants