You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by li...@apache.org on 2018/01/29 16:58:18 UTC
spark git commit: [SPARK-23059][SQL][TEST] Correct some improper with
view related method usage
Repository: spark
Updated Branches:
refs/heads/master 54dd7cf4e -> fbce2ed0f
[SPARK-23059][SQL][TEST] Correct some improper with view related method usage
## What changes were proposed in this pull request?
Correct some improper with view related method usage
Only change test cases
like:
```
test("list global temp views") {
try {
sql("CREATE GLOBAL TEMP VIEW v1 AS SELECT 3, 4")
sql("CREATE TEMP VIEW v2 AS SELECT 1, 2")
checkAnswer(sql(s"SHOW TABLES IN $globalTempDB"),
Row(globalTempDB, "v1", true) ::
Row("", "v2", true) :: Nil)
assert(spark.catalog.listTables(globalTempDB).collect().toSeq.map(_.name) == Seq("v1", "v2"))
} finally {
spark.catalog.dropTempView("v1")
spark.catalog.dropGlobalTempView("v2")
}
}
```
other change please review the code.
## How was this patch tested?
See test case.
Author: xubo245 <60...@qq.com>
Closes #20250 from xubo245/DropTempViewError.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/fbce2ed0
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/fbce2ed0
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/fbce2ed0
Branch: refs/heads/master
Commit: fbce2ed0fa5c3e9fb2bdf9d9741eb3ff0760f88c
Parents: 54dd7cf
Author: xubo245 <60...@qq.com>
Authored: Mon Jan 29 08:58:14 2018 -0800
Committer: gatorsmile <ga...@gmail.com>
Committed: Mon Jan 29 08:58:14 2018 -0800
----------------------------------------------------------------------
.../org/apache/spark/sql/SQLQuerySuite.scala | 48 ++++++++++----------
.../sql/execution/GlobalTempViewSuite.scala | 4 +-
.../spark/sql/execution/SQLViewSuite.scala | 36 +++++++++------
.../spark/sql/execution/command/DDLSuite.scala | 2 +-
.../sql/hive/MetastoreDataSourcesSuite.scala | 2 +-
.../sql/hive/execution/HiveSQLViewSuite.scala | 26 ++++++-----
.../sql/hive/execution/SQLQuerySuite.scala | 44 +++++++++---------
7 files changed, 88 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
index a79ab47..ffd736d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
@@ -1565,36 +1565,38 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
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")
- df
- .write
- .format("parquet")
- .save(path)
-
- // We don't support creating a temporary table while specifying a database
- intercept[AnalysisException] {
+ withTempView("db.t") {
+ val path = dir.toURI.toString
+ val df =
+ sparkContext.parallelize(1 to 10).map(i => (i, i.toString)).toDF("num", "str")
+ df
+ .write
+ .format("parquet")
+ .save(path)
+
+ // We don't support creating a temporary table while specifying a database
+ intercept[AnalysisException] {
+ spark.sql(
+ s"""
+ |CREATE TEMPORARY VIEW db.t
+ |USING parquet
+ |OPTIONS (
+ | path '$path'
+ |)
+ """.stripMargin)
+ }.getMessage
+
+ // If you use backticks to quote the name then it's OK.
spark.sql(
s"""
- |CREATE TEMPORARY VIEW db.t
+ |CREATE TEMPORARY VIEW `db.t`
|USING parquet
|OPTIONS (
| path '$path'
|)
""".stripMargin)
- }.getMessage
-
- // If you use backticks to quote the name then it's OK.
- spark.sql(
- s"""
- |CREATE TEMPORARY VIEW `db.t`
- |USING parquet
- |OPTIONS (
- | path '$path'
- |)
- """.stripMargin)
- checkAnswer(spark.table("`db.t`"), df)
+ checkAnswer(spark.table("`db.t`"), df)
+ }
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala
index dcc6fa6..972b47e 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala
@@ -134,8 +134,8 @@ class GlobalTempViewSuite extends QueryTest with SharedSQLContext {
assert(spark.catalog.listTables(globalTempDB).collect().toSeq.map(_.name) == Seq("v1", "v2"))
} finally {
- spark.catalog.dropTempView("v1")
- spark.catalog.dropGlobalTempView("v2")
+ spark.catalog.dropGlobalTempView("v1")
+ spark.catalog.dropTempView("v2")
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
index ce8fde2..8269d4d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
@@ -53,15 +53,17 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
}
test("create a temp view on a permanent view") {
- withView("jtv1", "temp_jtv1") {
- sql("CREATE VIEW jtv1 AS SELECT * FROM jt WHERE id > 3")
- sql("CREATE TEMPORARY VIEW temp_jtv1 AS SELECT * FROM jtv1 WHERE id < 6")
- checkAnswer(sql("select count(*) FROM temp_jtv1"), Row(2))
+ withView("jtv1") {
+ withTempView("temp_jtv1") {
+ sql("CREATE VIEW jtv1 AS SELECT * FROM jt WHERE id > 3")
+ sql("CREATE TEMPORARY VIEW temp_jtv1 AS SELECT * FROM jtv1 WHERE id < 6")
+ checkAnswer(sql("select count(*) FROM temp_jtv1"), Row(2))
+ }
}
}
test("create a temp view on a temp view") {
- withView("temp_jtv1", "temp_jtv2") {
+ withTempView("temp_jtv1", "temp_jtv2") {
sql("CREATE TEMPORARY VIEW temp_jtv1 AS SELECT * FROM jt WHERE id > 3")
sql("CREATE TEMPORARY VIEW temp_jtv2 AS SELECT * FROM temp_jtv1 WHERE id < 6")
checkAnswer(sql("select count(*) FROM temp_jtv2"), Row(2))
@@ -222,10 +224,12 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
}
test("error handling: disallow IF NOT EXISTS for CREATE TEMPORARY VIEW") {
- val e = intercept[AnalysisException] {
- sql("CREATE TEMPORARY VIEW IF NOT EXISTS myabcdview AS SELECT * FROM jt")
+ withTempView("myabcdview") {
+ val e = intercept[AnalysisException] {
+ sql("CREATE TEMPORARY VIEW IF NOT EXISTS myabcdview AS SELECT * FROM jt")
+ }
+ assert(e.message.contains("It is not allowed to define a TEMPORARY view with IF NOT EXISTS"))
}
- assert(e.message.contains("It is not allowed to define a TEMPORARY view with IF NOT EXISTS"))
}
test("error handling: fail if the temp view sql itself is invalid") {
@@ -274,7 +278,7 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
}
test("correctly parse CREATE TEMPORARY VIEW statement") {
- withView("testView") {
+ withTempView("testView") {
sql(
"""CREATE TEMPORARY VIEW
|testView (c1 COMMENT 'blabla', c2 COMMENT 'blabla')
@@ -286,7 +290,7 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
}
test("should NOT allow CREATE TEMPORARY VIEW when TEMPORARY VIEW with same name exists") {
- withView("testView") {
+ withTempView("testView") {
sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
val e = intercept[AnalysisException] {
@@ -299,15 +303,19 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
test("should allow CREATE TEMPORARY VIEW when a permanent VIEW with same name exists") {
withView("testView", "default.testView") {
- sql("CREATE VIEW testView AS SELECT id FROM jt")
- sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
+ withTempView("testView") {
+ sql("CREATE VIEW testView AS SELECT id FROM jt")
+ sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
+ }
}
}
test("should allow CREATE permanent VIEW when a TEMPORARY VIEW with same name exists") {
withView("testView", "default.testView") {
- sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
- sql("CREATE VIEW testView AS SELECT id FROM jt")
+ withTempView("testView") {
+ sql("CREATE TEMPORARY VIEW testView AS SELECT id FROM jt")
+ sql("CREATE VIEW testView AS SELECT id FROM jt")
+ }
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
index 6ca21b5..ee3674b 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
@@ -739,7 +739,7 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
// starts with 'jar:', and it is an illegal parameter for Path, so here we copy it
// to a temp file by withResourceTempPath
withResourceTempPath("test-data/cars.csv") { tmpFile =>
- withView("testview") {
+ withTempView("testview") {
sql(s"CREATE OR REPLACE TEMPORARY VIEW testview (c1 String, c2 String) USING " +
"org.apache.spark.sql.execution.datasources.csv.CSVFileFormat " +
s"OPTIONS (PATH '${tmpFile.toURI}')")
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
index fade143..859099a 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
@@ -1151,7 +1151,7 @@ class MetastoreDataSourcesSuite extends QueryTest with SQLTestUtils with TestHiv
test("create a temp view using hive") {
val tableName = "tab1"
- withTable(tableName) {
+ withTempView(tableName) {
val e = intercept[AnalysisException] {
sql(
s"""
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveSQLViewSuite.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveSQLViewSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveSQLViewSuite.scala
index 97e4c2b..5e6e114 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveSQLViewSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveSQLViewSuite.scala
@@ -67,20 +67,22 @@ class HiveSQLViewSuite extends SQLViewSuite with TestHiveSingleton {
classOf[org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper].getCanonicalName
withUserDefinedFunction(tempFunctionName -> true) {
sql(s"CREATE TEMPORARY FUNCTION $tempFunctionName AS '$functionClass'")
- withView("view1", "tempView1") {
- withTable("tab1") {
- (1 to 10).map(i => s"$i").toDF("id").write.saveAsTable("tab1")
+ withView("view1") {
+ withTempView("tempView1") {
+ withTable("tab1") {
+ (1 to 10).map(i => s"$i").toDF("id").write.saveAsTable("tab1")
- // temporary view
- sql(s"CREATE TEMPORARY VIEW tempView1 AS SELECT $tempFunctionName(id) from tab1")
- checkAnswer(sql("select count(*) FROM tempView1"), Row(10))
+ // temporary view
+ sql(s"CREATE TEMPORARY VIEW tempView1 AS SELECT $tempFunctionName(id) from tab1")
+ checkAnswer(sql("select count(*) FROM tempView1"), Row(10))
- // permanent view
- val e = intercept[AnalysisException] {
- sql(s"CREATE VIEW view1 AS SELECT $tempFunctionName(id) from tab1")
- }.getMessage
- assert(e.contains("Not allowed to create a permanent view `view1` by referencing " +
- s"a temporary function `$tempFunctionName`"))
+ // permanent view
+ val e = intercept[AnalysisException] {
+ sql(s"CREATE VIEW view1 AS SELECT $tempFunctionName(id) from tab1")
+ }.getMessage
+ assert(e.contains("Not allowed to create a permanent view `view1` by referencing " +
+ s"a temporary function `$tempFunctionName`"))
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/fbce2ed0/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
----------------------------------------------------------------------
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 33bcae9..baabc4a 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
@@ -1203,35 +1203,37 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
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")
- df
- .write
- .format("parquet")
- .save(path)
-
- // We don't support creating a temporary table while specifying a database
- intercept[AnalysisException] {
+ withTempView("db.t") {
+ val path = dir.toURI.toString
+ val df = sparkContext.parallelize(1 to 10).map(i => (i, i.toString)).toDF("num", "str")
+ df
+ .write
+ .format("parquet")
+ .save(path)
+
+ // We don't support creating a temporary table while specifying a database
+ intercept[AnalysisException] {
+ spark.sql(
+ s"""
+ |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 VIEW db.t
+ |CREATE TEMPORARY VIEW `db.t`
|USING parquet
|OPTIONS (
| path '$path'
|)
""".stripMargin)
+ checkAnswer(spark.table("`db.t`"), df)
}
-
- // If you use backticks to quote the name then it's OK.
- spark.sql(
- s"""
- |CREATE TEMPORARY VIEW `db.t`
- |USING parquet
- |OPTIONS (
- | path '$path'
- |)
- """.stripMargin)
- checkAnswer(spark.table("`db.t`"), df)
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org