diff options
author | Xin Wu <xinwu@us.ibm.com> | 2017-02-13 19:45:58 -0800 |
---|---|---|
committer | Xiao Li <gatorsmile@gmail.com> | 2017-02-13 19:45:58 -0800 |
commit | 1ab97310e83ee138a1b210c0dfa89a341f1d530a (patch) | |
tree | d73150111baf59f4c16af65cf4ea8a3c1607ee4e /sql/hive | |
parent | 6e45b547ceadbbe8394bf149945b7942df82660a (diff) | |
download | spark-1ab97310e83ee138a1b210c0dfa89a341f1d530a.tar.gz spark-1ab97310e83ee138a1b210c0dfa89a341f1d530a.tar.bz2 spark-1ab97310e83ee138a1b210c0dfa89a341f1d530a.zip |
[SPARK-19539][SQL] Block duplicate temp table during creation
## 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 #16878 from xwu0226/block_duplicate_temp_table.
Diffstat (limited to 'sql/hive')
-rw-r--r-- | sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala | 8 | ||||
-rw-r--r-- | sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala | 18 |
2 files changed, 13 insertions, 13 deletions
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala index 8fda1c5875..6937e97a47 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala @@ -148,8 +148,8 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY TABLE parquet_temp (c1 INT, c2 STRING) - |USING org.apache.spark.sql.parquet.DefaultSource + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) + |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) // An empty sequence of row is returned for session temporary table. @@ -401,8 +401,8 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY TABLE parquet_temp (c1 INT, c2 STRING) - |USING org.apache.spark.sql.parquet.DefaultSource + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) + |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) // An empty sequence of row is returned for session temporary table. intercept[NoSuchTableException] { diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala index 20f30e48ab..faed8b5046 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala @@ -1290,7 +1290,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { "interval 4 minutes 59 seconds 889 milliseconds 987 microseconds"))) } - test("specifying database name for a temporary table is not allowed") { + test("specifying database name for a temporary view is not allowed") { withTempPath { dir => val path = dir.toURI.toString val df = sparkContext.parallelize(1 to 10).map(i => (i, i.toString)).toDF("num", "str") @@ -1303,23 +1303,23 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { intercept[AnalysisException] { spark.sql( s""" - |CREATE TEMPORARY TABLE db.t - |USING parquet - |OPTIONS ( - | path '$path' - |) - """.stripMargin) + |CREATE TEMPORARY VIEW db.t + |USING parquet + |OPTIONS ( + | path '$path' + |) + """.stripMargin) } // If you use backticks to quote the name then it's OK. spark.sql( s""" - |CREATE TEMPORARY TABLE `db.t` + |CREATE TEMPORARY VIEW `db.t` |USING parquet |OPTIONS ( | path '$path' |) - """.stripMargin) + """.stripMargin) checkAnswer(spark.table("`db.t`"), df) } } |