Github user windpiger commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17055#discussion_r105526116
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala 
---
    @@ -2016,48 +2016,79 @@ abstract class DDLSuite extends QueryTest with 
SQLTestUtils {
         }
       }
     
    +  test("create datasource table with a non-existing location") {
    +    withTable("t", "t1") {
    +      withTempPath { dir =>
    +        spark.sql(s"CREATE TABLE t(a int, b int) USING parquet LOCATION 
'$dir'")
    +
    +        val table = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
    +        assert(table.location == makeQualifiedPath(dir.getAbsolutePath))
    +
    +        spark.sql("INSERT INTO TABLE t SELECT 1, 2")
    +        assert(dir.exists())
    +
    +        checkAnswer(spark.table("t"), Row(1, 2))
    +      }
    +      // partition table
    +      withTempPath { dir =>
    +        spark.sql(
    +          s"""
    +             |CREATE TABLE t1(a int, b int) USING parquet PARTITIONED 
BY(a) LOCATION '$dir'
    +           """.stripMargin)
    +
    +        val table = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t1"))
    +        assert(table.location == makeQualifiedPath(dir.getAbsolutePath))
    +
    +        spark.sql("INSERT INTO TABLE t1 PARTITION(a=1) SELECT 2")
    +
    +        val partDir = new File(dir, "a=1")
    +        assert(partDir.exists())
    +
    +        checkAnswer(spark.table("t1"), Row(2, 1))
    +      }
    +    }
    +  }
    +
       Seq(true, false).foreach { shouldDelete =>
    -    val tcName = if (shouldDelete) "non-existent" else "existed"
    +    val tcName = if (shouldDelete) "non-existing" else "existed"
         test(s"CTAS for external data source table with a $tcName location") {
           withTable("t", "t1") {
    -        withTempDir {
    -          dir =>
    -            if (shouldDelete) {
    -              dir.delete()
    -            }
    -            spark.sql(
    -              s"""
    -                 |CREATE TABLE t
    -                 |USING parquet
    -                 |LOCATION '$dir'
    -                 |AS SELECT 3 as a, 4 as b, 1 as c, 2 as d
    -               """.stripMargin)
    -            val table = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
    -            assert(table.location == 
makeQualifiedPath(dir.getAbsolutePath))
    +        withTempDir { dir =>
    +          if (shouldDelete) {
    +            dir.delete()
    +          }
    --- End diff --
    
    ok thanks~~


---
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]

Reply via email to