Skip to content

Commit d4378dd

Browse files
committed
optimize some code
1 parent 0e09b92 commit d4378dd

2 files changed

Lines changed: 11 additions & 45 deletions

File tree

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,15 +1952,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
19521952

19531953
test("create datasource table with a non-existing location") {
19541954
withTable("t", "t1") {
1955-
withTempDir {
1956-
dir =>
1957-
dir.delete()
1958-
spark.sql(
1959-
s"""
1960-
|CREATE TABLE t(a int, b int)
1961-
|USING parquet
1962-
|LOCATION '$dir'
1963-
""".stripMargin)
1955+
withTempPath { dir =>
1956+
spark.sql(s"CREATE TABLE t(a int, b int) USING parquet LOCATION '$dir'")
19641957

19651958
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
19661959
assert(table.location == dir.getAbsolutePath)
@@ -1971,16 +1964,9 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
19711964
checkAnswer(spark.table("t"), Row(1, 2))
19721965
}
19731966
// partition table
1974-
withTempDir {
1967+
withTempPath {
19751968
dir =>
1976-
dir.delete()
1977-
spark.sql(
1978-
s"""
1979-
|CREATE TABLE t1(a int, b int)
1980-
|USING parquet
1981-
|PARTITIONED BY(a)
1982-
|LOCATION '$dir'
1983-
""".stripMargin)
1969+
spark.sql(s"CREATE TABLE t1(a int, b int) USING parquet PARTITIONED BY(a) LOCATION '$dir'")
19841970

19851971
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t1"))
19861972
assert(table.location == dir.getAbsolutePath)

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,15 +1590,9 @@ class HiveDDLSuite
15901590

15911591
test("create datasource table with a non-existing location") {
15921592
withTable("t", "t1") {
1593-
withTempDir {
1593+
withTempPath {
15941594
dir =>
1595-
dir.delete()
1596-
spark.sql(
1597-
s"""
1598-
|CREATE TABLE t(a int, b int)
1599-
|USING parquet
1600-
|LOCATION '$dir'
1601-
""".stripMargin)
1595+
spark.sql(s"CREATE TABLE t(a int, b int) USING parquet LOCATION '$dir'")
16021596

16031597
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
16041598
assert(table.location == dir.getAbsolutePath)
@@ -1609,16 +1603,9 @@ class HiveDDLSuite
16091603
checkAnswer(spark.table("t"), Row(1, 2))
16101604
}
16111605
// partition table
1612-
withTempDir {
1606+
withTempPath {
16131607
dir =>
1614-
dir.delete()
1615-
spark.sql(
1616-
s"""
1617-
|CREATE TABLE t1(a int, b int)
1618-
|USING parquet
1619-
|PARTITIONED BY(a)
1620-
|LOCATION '$dir'
1621-
""".stripMargin)
1608+
spark.sql(s"CREATE TABLE t1(a int, b int) USING parquet PARTITIONED BY(a) LOCATION '$dir'")
16221609

16231610
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t1"))
16241611
assert(table.location == dir.getAbsolutePath)
@@ -1635,15 +1622,9 @@ class HiveDDLSuite
16351622

16361623
test("create hive table with a non-existing location") {
16371624
withTable("t", "t1") {
1638-
withTempDir {
1625+
withTempPath {
16391626
dir =>
1640-
dir.delete()
1641-
spark.sql(
1642-
s"""
1643-
|CREATE TABLE t(a int, b int)
1644-
|USING hive
1645-
|LOCATION '$dir'
1646-
""".stripMargin)
1627+
spark.sql(s"CREATE TABLE t(a int, b int) USING hive LOCATION '$dir'")
16471628

16481629
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
16491630
val dirPath = new Path(dir.getAbsolutePath)
@@ -1656,9 +1637,8 @@ class HiveDDLSuite
16561637
checkAnswer(spark.table("t"), Row(1, 2))
16571638
}
16581639
// partition table
1659-
withTempDir {
1640+
withTempPath {
16601641
dir =>
1661-
dir.delete()
16621642
spark.sql(
16631643
s"""
16641644
|CREATE TABLE t1(a int, b int)

0 commit comments

Comments
 (0)