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

    https://github.com/apache/spark/pull/16910#discussion_r102076290
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala 
---
    @@ -1494,4 +1495,149 @@ class HiveDDLSuite
           }
         }
       }
    +
    +  test("insert data to a hive serde table which has a not existed location 
should succeed") {
    +    withTable("t") {
    +      withTempDir { dir =>
    +        spark.sql(
    +          s"""
    +              |CREATE TABLE t(a string, b int)
    +              |USING hive
    +              |OPTIONS(path "file:${dir.getCanonicalPath}")
    +           """.stripMargin)
    +        val table = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
    +        val expectedPath = s"file:${dir.getAbsolutePath.stripSuffix("/")}"
    +        assert(table.location.stripSuffix("/") == expectedPath)
    +
    +        val tableLocFile = new File(table.location.stripPrefix("file:"))
    +        tableLocFile.delete()
    +        assert(!tableLocFile.exists())
    +        spark.sql("INSERT INTO TABLE t SELECT 'c', 1")
    +        assert(tableLocFile.exists())
    +        checkAnswer(spark.table("t"), Row("c", 1) :: Nil)
    +
    +        Utils.deleteRecursively(dir)
    +        assert(!tableLocFile.exists())
    +        spark.sql("INSERT OVERWRITE TABLE t SELECT 'c', 1")
    +        assert(tableLocFile.exists())
    +        checkAnswer(spark.table("t"), Row("c", 1) :: Nil)
    +
    +        val newDir = dir.getAbsolutePath.stripSuffix("/") + "/x"
    +        val newDirFile = new File(newDir)
    +        spark.sql(s"ALTER TABLE t SET LOCATION '$newDir'")
    +        spark.sessionState.catalog.refreshTable(TableIdentifier("t"))
    +
    +        val table1 = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
    +        assert(table1.location == newDir)
    +        assert(!newDirFile.exists())
    +
    +        spark.sql("INSERT INTO TABLE t SELECT 'c', 1")
    +        checkAnswer(spark.table("t"), Row("c", 1) :: Nil)
    +        assert(newDirFile.exists())
    +      }
    +    }
    +  }
    +
    +  test("insert into a hive serde table with no existed partition location 
should succeed") {
    +    withTable("t") {
    +      withTempDir { dir =>
    +        spark.sql(
    +          s"""
    +              |CREATE TABLE t(a int, b int, c int, d int)
    +              |USING hive
    +              |PARTITIONED BY(a, b)
    +              |LOCATION "file:${dir.getCanonicalPath}"
    +           """.stripMargin)
    +        val table = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
    +        val expectedPath = s"file:${dir.getAbsolutePath.stripSuffix("/")}"
    +        assert(table.location.stripSuffix("/") == expectedPath)
    +
    +        spark.sql("INSERT INTO TABLE t PARTITION(a=1, b=2) SELECT 3, 4")
    +        checkAnswer(spark.table("t"), Row(3, 4, 1, 2) :: Nil)
    +
    +        val partLoc = new File(s"${dir.getAbsolutePath}/a=1")
    +        Utils.deleteRecursively(partLoc)
    +        assert(!partLoc.exists())
    +        // insert overwrite into a partition which location has been 
deleted.
    +        spark.sql("INSERT OVERWRITE TABLE t PARTITION(a=1, b=2) SELECT 7, 
8")
    +        assert(partLoc.exists())
    +        checkAnswer(spark.table("t"), Row(7, 8, 1, 2) :: Nil)
    +
    +        val newDir = dir.getAbsolutePath.stripSuffix("/") + "/x"
    +        val newDirFile = new File(newDir)
    +        spark.sql(s"ALTER TABLE t PARTITION(a=1, b=2) SET LOCATION 
'$newDir'")
    +        assert(!newDirFile.exists())
    +
    +        // insert into a partition which location does not exists.
    +        spark.sql("INSERT INTO TABLE t PARTITION(a=1, b=2) SELECT 9, 10")
    +        assert(newDirFile.exists())
    +        checkAnswer(spark.table("t"), Row(9, 10, 1, 2) :: Nil)
    +      }
    +    }
    +  }
    +
    +  test("read data from a hive serde table which has a not existed location 
should succeed") {
    --- End diff --
    
    This is the only test case failed without this fix. Right?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to