GitHub user gatorsmile opened a pull request:

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

    [SPARK-16803] [SQL] SaveAsTable does not work when source DataFrame is 
built on a Hive Table

    ### What changes were proposed in this pull request?
    In Spark 2.0, `SaveAsTable` does not work when source DataFrame is built on 
a Hive Table, but Spark 1.6 works.
    
    **Spark 1.6**
    ```Scala
    scala> sql("create table sample.sample stored as SEQUENCEFILE as select 1 
as key, 'abc' as value")
    res2: org.apache.spark.sql.DataFrame = []
    
    scala> val df = sql("select key, value as value from sample.sample")
    df: org.apache.spark.sql.DataFrame = [key: int, value: string]
    
    scala> df.write.mode("append").saveAsTable("sample.sample")
    
    scala> sql("select * from sample.sample").show()
    +---+-----+
    |key|value|
    +---+-----+
    |  1|  abc|
    |  1|  abc|
    +---+-----+
    ```
    **Spark 2.0**
    ```Scala
    scala> df.write.mode("append").saveAsTable("sample.sample")
    org.apache.spark.sql.AnalysisException: Saving data in MetastoreRelation 
sample, sample
     is not supported.;
    ```
    
    So far, we do not plan to support it in Spark 2.0. Spark 1.6 works because 
it internally uses {{insertInto}}. But, if we change it back it will break the 
semantic of {{saveAsTable}} (this method uses by-name resolution instead of 
using by-position resolution used by {{insertInto}}).
    
    Instead, users should use {{insertInto}} API. This PR corrects the error 
messages. Users can understand how to bypass it before we support it in a 
separate PR.
    
    ### How was this patch tested?
    Test cases are added

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

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

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

    https://github.com/apache/spark/pull/14410.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 #14410
    
----
commit 724fcf8d2a721d100644e8dd3d17dad52bb9ce09
Author: gatorsmile <[email protected]>
Date:   2016-07-29T21:14:11Z

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