GitHub user gatorsmile opened a pull request:

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

    [SPARK-16803] [SQL] SaveAsTable does not work when target table is a Hive 
serde table

    ### What changes were proposed in this pull request?
    
    In Spark 2.0, `SaveAsTable` does not work when the target table is a Hive 
serde 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.1 due to the risk. 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). More extra changes 
are needed to support `hive` as a `format` in DataFrameWriter.
    
    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 saveAsTableFix5

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

    https://github.com/apache/spark/pull/15926.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 #15926
    
----
commit 887b4275d26bb04783abee6c72607b62c41034bf
Author: gatorsmile <[email protected]>
Date:   2016-11-18T02:16:13Z

    fix

commit 061c0d34aa7b5b64b7fa490e969d11c7733bc26f
Author: gatorsmile <[email protected]>
Date:   2016-11-18T02:29:33Z

    improve the error message

----


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