You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gatorsmile <gi...@git.apache.org> on 2016/09/04 07:03:44 UTC

[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

GitHub user gatorsmile opened a pull request:

    https://github.com/apache/spark/pull/14954

    [SPARK-17393] [SQL] Error Handling when CTAS Against the Same Data Source Table Using Overwrite Mode

    ### What changes were proposed in this pull request?
    When we trying to read a table and then write to the same table using the `Overwrite` save mode, we got a very confusing error message:
    For example, 
    ```Scala
          Seq((1, 2)).toDF("i", "j").write.saveAsTable("tab1")
          table("tab1").write.mode(SaveMode.Overwrite).saveAsTable("tab1")
    ```
    
    ```
    Job aborted.
    org.apache.spark.SparkException: Job aborted.
    	at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand$$anonfun$run$1.apply$mcV$sp
    ...
    Caused by: org.apache.spark.SparkException: Task failed while writing rows
    	at org.apache.spark.sql.execution.datasources.DefaultWriterContainer.writeRows(WriterContainer.scala:266)
    	at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand$$anonfun$run$1$$anonfun$apply$mcV$sp$1.apply(InsertIntoHadoopFsRelationCommand.scala:143)
    	at org.apache.spark.sql.execution.datasources
    ```
    
    After the PR, we will issue an `AnalysisException`:
    ```
    Cannot overwrite table `tab1` that is also being read from
    ```
    ### How was this patch tested?
    Added test cases.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gatorsmile/spark ctasQueryAnalyze

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/14954.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #14954
    
----
commit 85e51dc6361b3607fafc95021d93f791f5947080
Author: gatorsmile <ga...@gmail.com>
Date:   2016-09-04T06:49:41Z

    fix.

----


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

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


[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14954#discussion_r77467255
  
    --- 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 --
    
    yea I think we should, let's do it in follow-up PR


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

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


[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

Posted by gatorsmile <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/14954


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    **[Test build #64914 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64914/consoleFull)** for PR 14954 at commit [`85e51dc`](https://github.com/apache/spark/commit/85e51dc6361b3607fafc95021d93f791f5947080).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    cc @cloud-fan @yhuai 


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    Merged build finished. Test PASSed.


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64914/
    Test PASSed.


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    LGTM, merging to master!



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

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


[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14954#discussion_r77468619
  
    --- 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 --
    
    Sure, will do it. 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #14954: [SPARK-17393] [SQL] Error Handling when CTAS Agai...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14954#discussion_r77467164
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala ---
    @@ -357,32 +376,6 @@ case class PreWriteCheck(conf: SQLConf, catalog: SessionCatalog)
             // The relation in l is not an InsertableRelation.
             failAnalysis(s"$l does not allow insertion.")
     
    -      case CreateTable(tableDesc, mode, Some(query)) =>
    --- End diff --
    
    ah good catch! This branch is actually unreachable.


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

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


[GitHub] spark issue #14954: [SPARK-17393] [SQL] Error Handling when CTAS Against the...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/14954
  
    **[Test build #64914 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64914/consoleFull)** for PR 14954 at commit [`85e51dc`](https://github.com/apache/spark/commit/85e51dc6361b3607fafc95021d93f791f5947080).


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

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