Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/13451#discussion_r65489722
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/sources/CreateTableAsSelectSuite.scala
---
@@ -40,172 +43,175 @@ class CreateTableAsSelectSuite extends DataSourceTest
with SharedSQLContext with
override def afterAll(): Unit = {
try {
spark.catalog.dropTempView("jt")
+ if (path.exists()) {
+ Utils.deleteRecursively(path)
+ }
} finally {
super.afterAll()
}
}
- after {
- Utils.deleteRecursively(path)
+ before {
+ if (path.exists()) {
+ Utils.deleteRecursively(path)
+ }
}
- test("CREATE TEMPORARY TABLE AS SELECT") {
- sql(
- s"""
- |CREATE TEMPORARY TABLE jsonTable
- |USING json
- |OPTIONS (
- | path '${path.toString}'
- |) AS
- |SELECT a, b FROM jt
- """.stripMargin)
-
- checkAnswer(
- sql("SELECT a, b FROM jsonTable"),
- sql("SELECT a, b FROM jt").collect())
-
- spark.catalog.dropTempView("jsonTable")
+ test("CREATE TABLE USING AS SELECT") {
+ withTable("jsonTable") {
+ sql(
+ s"""
+ |CREATE TABLE jsonTable
+ |USING json
+ |OPTIONS (
+ | path '${path.toString}'
+ |) AS
+ |SELECT a, b FROM jt
+ """.stripMargin)
+
+ checkAnswer(
+ sql("SELECT a, b FROM jsonTable"),
+ sql("SELECT a, b FROM jt").collect())
+ }
}
- test("CREATE TEMPORARY TABLE AS SELECT based on the file without write
permission") {
+ test("CREATE TABLE USING AS SELECT based on the file without write
permission") {
val childPath = new File(path.toString, "child")
path.mkdir()
- childPath.createNewFile()
path.setWritable(false)
- val e = intercept[IOException] {
+ val e = intercept[Exception] {
sql(
s"""
- |CREATE TEMPORARY TABLE jsonTable
+ |CREATE TABLE jsonTable
|USING json
|OPTIONS (
- | path '${path.toString}'
+ | path '${childPath.toString}'
|) AS
|SELECT a, b FROM jt
- """.stripMargin)
+ """.stripMargin)
sql("SELECT a, b FROM jsonTable").collect()
}
- assert(e.getMessage().contains("Unable to clear output directory"))
+ assert(e.getMessage().contains("Job aborted"))
path.setWritable(true)
}
test("create a table, drop it and create another one with the same
name") {
- sql(
- s"""
- |CREATE TEMPORARY TABLE jsonTable
- |USING json
- |OPTIONS (
- | path '${path.toString}'
- |) AS
- |SELECT a, b FROM jt
- """.stripMargin)
-
- checkAnswer(
- sql("SELECT a, b FROM jsonTable"),
- sql("SELECT a, b FROM jt").collect())
-
- val message = intercept[ParseException]{
+ withTable("jsonTable") {
sql(
s"""
- |CREATE TEMPORARY TABLE IF NOT EXISTS jsonTable
- |USING json
- |OPTIONS (
- | path '${path.toString}'
- |) AS
- |SELECT a * 4 FROM jt
- """.stripMargin)
- }.getMessage
- assert(message.toLowerCase.contains("operation not allowed"))
-
- // Overwrite the temporary table.
- sql(
- s"""
- |CREATE TEMPORARY TABLE jsonTable
- |USING json
- |OPTIONS (
- | path '${path.toString}'
- |) AS
- |SELECT a * 4 FROM jt
- """.stripMargin)
- checkAnswer(
- sql("SELECT * FROM jsonTable"),
- sql("SELECT a * 4 FROM jt").collect())
-
- spark.catalog.dropTempView("jsonTable")
- // Explicitly delete the data.
- if (path.exists()) Utils.deleteRecursively(path)
-
- sql(
- s"""
- |CREATE TEMPORARY TABLE jsonTable
- |USING json
- |OPTIONS (
- | path '${path.toString}'
- |) AS
- |SELECT b FROM jt
- """.stripMargin)
-
- checkAnswer(
- sql("SELECT * FROM jsonTable"),
- sql("SELECT b FROM jt").collect())
-
- spark.catalog.dropTempView("jsonTable")
- }
+ |CREATE TABLE jsonTable
+ |USING json
+ |OPTIONS (
+ | path '${path.toString}'
+ |) AS
+ |SELECT a, b FROM jt
+ """.stripMargin)
+
+ checkAnswer(
+ sql("SELECT a, b FROM jsonTable"),
+ sql("SELECT a, b FROM jt").collect())
--- End diff --
Nit: The same here. You do not need to call `collect`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]