GitHub user gatorsmile opened a pull request:

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

    [SPARK-20476] [SQL] Block users to create a table that use commas in the 
column names

    ### What changes were proposed in this pull request?
    ```SQL
    hive> create table t1(`a,` string);
    OK
    Time taken: 1.399 seconds
    
    hive> create table t2(`a,` string, b string);
    FAILED: Execution Error, return code 1 from 
org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: 
MetaException(message:org.apache.hadoop.hive.serde2.SerDeException 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe: columns has 3 elements 
while columns.types has 2 elements!)
    
    hive> create table t2(`a,` string, b string) stored as parquet;
    FAILED: Execution Error, return code 1 from 
org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.IllegalArgumentException: 
ParquetHiveSerde initialization failed. Number of column name and column type 
differs. columnNames = [a, , b], columnTypes = [string, string]
    ```
    It has a bug in Hive metastore. 
    
    When users do not provide alias name in the SELECT query, we call 
`toPrettySQL` to generate the alias name. For example, the string 
`get_json_object(jstring, '$.f1')` will be the alias name for the function call 
in the statement 
    ```SQL
    SELECT key, get_json_object(jstring, '$.f1') FROM tempView
    ``` 
    Above is not an issue for the SELECT query statements. However, for CTAS, 
we hit the issue due to a bug in Hive metastore. Hive metastore does not like 
the column names containing commas and returned a confusing error message, like:
    ```
    17/04/26 23:12:56 ERROR [hive.log(397) -- main]: error in initSerDe: 
org.apache.hadoop.hive.serde2.SerDeException 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe: columns has 2 elements 
while columns.types has 1 elements!
    org.apache.hadoop.hive.serde2.SerDeException: 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe: columns has 2 elements 
while columns.types has 1 elements!
    ```
    
    Thus, this PR is to block users to create a table in Hive metastore when 
the table table has a column containing commas in the name. 
    
    ### How was this patch tested?
    Added a test case

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

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

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

    https://github.com/apache/spark/pull/17781.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 #17781
    
----
commit 9563de4b54233f1f2148dac20178b7b8c4ff1f41
Author: Xiao Li <gatorsm...@gmail.com>
Date:   2017-04-27T06:24:39Z

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

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

Reply via email to