GitHub user bomeng opened a pull request:

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

    [SPARK-15230] [SQL] distinct() does not handle column name with dot properly

    ## What changes were proposed in this pull request?
    
    When table is created with column name containing dot, distinct() will fail 
to run. For example,
    ```scala
    val rowRDD = sparkContext.parallelize(Seq(Row(1), Row(1), Row(2)))
    val schema = StructType(Array(StructField("column.with.dot", IntegerType, 
nullable = false)))
    val df = spark.createDataFrame(rowRDD, schema)
    ```
    running the following will have no problem: 
    ```scala
    df.select(new Column("`column.with.dot`"))
    ```
    but running the query with additional distinct() will cause exception:
    ```scala
    df.select(new Column("`column.with.dot`")).distinct()
    ```
    
    The issue is that distinct() will try to resolve the column name, but the 
column name in the schema does not have backtick with it. So the solution is to 
add the backtick before passing the column name to resolve().
    
    ## How was this patch tested?
    
    Added a new test case.
    


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

    $ git pull https://github.com/bomeng/spark SPARK-15230

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

    https://github.com/apache/spark/pull/13140.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 #13140
    
----
commit 2f7ffbd58a3437898f32e7603ca6b603f5fd5088
Author: bomeng <bm...@us.ibm.com>
Date:   2016-05-16T20:37:54Z

    fix distinct()

----


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