Skip to content

Commit 8559e4e

Browse files
committed
add test in DDLSuit
1 parent 058865b commit 8559e4e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ case class DataSource(
440440

441441
if (mode == SaveMode.Append) false
442442
else if (mode == SaveMode.Overwrite) true
443-
else throw new IllegalStateException(s"unsupported save mode $mode")
443+
else {
444+
throw new IllegalStateException(s"unsupported save mode $mode")
445+
}
444446
} else true
445447
}
446448

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,4 +1832,28 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
18321832
}
18331833
}
18341834
}
1835+
1836+
test("CTAS for data source table with a created location") {
1837+
withTable("t") {
1838+
withTempDir {
1839+
dir =>
1840+
spark.sql(
1841+
s"""
1842+
|CREATE TABLE t
1843+
|USING parquet
1844+
|PARTITIONED BY(a, b)
1845+
|LOCATION '$dir'
1846+
|AS SELECT 3 as a, 4 as b, 1 as c, 2 as d
1847+
""".stripMargin)
1848+
1849+
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
1850+
assert(table.location.stripSuffix("/") == dir.getAbsolutePath.stripSuffix("/"))
1851+
1852+
val partDir = new File(dir.getAbsolutePath + "/a=3")
1853+
assert(partDir.exists())
1854+
1855+
checkAnswer(spark.table("t"), Row(1, 2, 3, 4))
1856+
}
1857+
}
1858+
}
18351859
}

0 commit comments

Comments
 (0)