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

    https://github.com/apache/spark/pull/14954#discussion_r77456629
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
 ---
    @@ -1151,6 +1151,58 @@ class MetastoreDataSourcesSuite extends QueryTest 
with SQLTestUtils with TestHiv
         }
       }
     
    +  test("saveAsTable - source and target are the same table") {
    +    val tableName = "tab1"
    +    withTable(tableName) {
    +      Seq((1, 2)).toDF("i", "j").write.saveAsTable(tableName)
    +
    +      table(tableName).write.mode(SaveMode.Append).saveAsTable(tableName)
    +      checkAnswer(table(tableName),
    +        Seq(Row(1, 2), Row(1, 2)))
    +
    +      table(tableName).write.mode(SaveMode.Ignore).saveAsTable(tableName)
    +      checkAnswer(table(tableName),
    +        Seq(Row(1, 2), Row(1, 2)))
    +
    +      var e = intercept[AnalysisException] {
    +        
table(tableName).write.mode(SaveMode.Overwrite).saveAsTable(tableName)
    +      }.getMessage
    +      assert(e.contains(s"Cannot overwrite table `$tableName` that is also 
being read from"))
    +
    +      e = intercept[AnalysisException] {
    +        
table(tableName).write.mode(SaveMode.ErrorIfExists).saveAsTable(tableName)
    +      }.getMessage
    +      assert(e.contains(s"Table `$tableName` already exists"))
    +    }
    +  }
    +
    +  test("insertInto - source and target are the same table") {
    +    val tableName = "tab1"
    +    withTable(tableName) {
    +      Seq((1, 2)).toDF("i", "j").write.saveAsTable(tableName)
    +
    +      table(tableName).write.mode(SaveMode.Append).insertInto(tableName)
    +      checkAnswer(
    +        table(tableName),
    +        Seq(Row(1, 2), Row(1, 2)))
    +
    +      table(tableName).write.mode(SaveMode.Ignore).insertInto(tableName)
    --- End diff --
    
    Should we issue error messages when the operation is `insertInto` but the 
mode is `Ignore` or `ErrorIfExists`?


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