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

    https://github.com/apache/spark/pull/18050#discussion_r117658942
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/InsertIntoHiveTableSuite.scala
 ---
    @@ -166,72 +166,54 @@ class InsertIntoHiveTableSuite extends QueryTest with 
TestHiveSingleton with Bef
         sql("DROP TABLE tmp_table")
       }
     
    -  test("INSERT OVERWRITE - partition IF NOT EXISTS") {
    -    withTempDir { tmpDir =>
    -      val table = "table_with_partition"
    -      withTable(table) {
    -        val selQuery = s"select c1, p1, p2 from $table"
    -        sql(
    -          s"""
    -             |CREATE TABLE $table(c1 string)
    -             |PARTITIONED by (p1 string,p2 string)
    -             |location '${tmpDir.toURI.toString}'
    -           """.stripMargin)
    -        sql(
    -          s"""
    -             |INSERT OVERWRITE TABLE $table
    -             |partition (p1='a',p2='b')
    -             |SELECT 'blarr'
    -           """.stripMargin)
    -        checkAnswer(
    -          sql(selQuery),
    -          Row("blarr", "a", "b"))
    -
    -        sql(
    -          s"""
    -             |INSERT OVERWRITE TABLE $table
    -             |partition (p1='a',p2='b')
    -             |SELECT 'blarr2'
    -           """.stripMargin)
    -        checkAnswer(
    -          sql(selQuery),
    -          Row("blarr2", "a", "b"))
    +  testPartitionedTable("INSERT OVERWRITE - partition IF NOT EXISTS") { 
tableName =>
    +    val selQuery = s"select a, b, c, d from $tableName"
    +    sql(
    +      s"""
    +         |INSERT OVERWRITE TABLE $tableName
    +         |partition (b=2, c=3)
    +         |SELECT 1, 4
    +        """.stripMargin)
    +    checkAnswer(sql(selQuery), Row(1, 2, 3, 4))
     
    -        var e = intercept[AnalysisException] {
    -          sql(
    -            s"""
    -               |INSERT OVERWRITE TABLE $table
    -               |partition (p1='a',p2) IF NOT EXISTS
    -               |SELECT 'blarr3', 'newPartition'
    -             """.stripMargin)
    -        }
    -        assert(e.getMessage.contains(
    -          "Dynamic partitions do not support IF NOT EXISTS. Specified 
partitions with value: [p2]"))
    +    sql(
    +      s"""
    +         |INSERT OVERWRITE TABLE $tableName
    +         |partition (b=2, c=3)
    +         |SELECT 5, 6
    +        """.stripMargin)
    +    checkAnswer(sql(selQuery), Row(5, 2, 3, 6))
    +
    +    val e = intercept[AnalysisException] {
    +      sql(
    +        s"""
    +           |INSERT OVERWRITE TABLE $tableName
    +           |partition (b=2, c) IF NOT EXISTS
    +           |SELECT 7, 8, 3
    +          """.stripMargin)
    +    }
    +    assert(e.getMessage.contains(
    +      "Dynamic partitions do not support IF NOT EXISTS. Specified 
partitions with value: [c]"))
     
    -        e = intercept[AnalysisException] {
    -          sql(
    -            s"""
    -               |INSERT OVERWRITE TABLE $table
    -               |partition (p1='a',p2) IF NOT EXISTS
    -               |SELECT 'blarr3', 'b'
    -             """.stripMargin)
    -        }
    -        assert(e.getMessage.contains(
    -          "Dynamic partitions do not support IF NOT EXISTS. Specified 
partitions with value: [p2]"))
    +    // If the partition already exists, the insert will overwrite the data
    +    // unless users specify IF NOT EXISTS
    +    sql(
    +      s"""
    +         |INSERT OVERWRITE TABLE $tableName
    +         |partition (b=2, c=3) IF NOT EXISTS
    +         |SELECT 9, 10
    +        """.stripMargin)
    +    checkAnswer(sql(selQuery), Row(5, 2, 3, 6))
     
    -        // If the partition already exists, the insert will overwrite the 
data
    --- End diff --
    
    That is why I used `testPartitionedTable` to do the test. It tests both 
data source and hive serde tables. 


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