GitHub user dongjoon-hyun opened a pull request:

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

    [SPARK-14664][SQL] Fix DecimalAggregates optimizer not to break Window 
queries

    ## What changes were proposed in this pull request?
    
    Historically, `DecimalAggregates` optimizer is designed to transform 
general `sum/avg(decimal)`.
    However, it breaks recently added windows queries like the followings. The 
following queries work well without this optimizer.
    
    **Sum**
    ```scala
    scala> sql("select sum(a) over () from (select explode(array(1.0,2.0)) a) 
t").head
    java.lang.RuntimeException: Unsupported window function: 
MakeDecimal((sum(UnscaledValue(a#31)),mode=Complete,isDistinct=false),12,1)
    ```
    
    **Average**
    ```scala
    scala> sql("select avg(a) over () from (select explode(array(1.0,2.0)) a) 
t").head
    java.lang.RuntimeException: Unsupported window function: 
cast(((avg(UnscaledValue(a#40)),mode=Complete,isDistinct=false) / 10.0) as 
decimal(6,5))
    ```
    
    This PR aims to fix `DecimalAggregates` optimizer not to handle aggregation 
queries over windows.
    Note that this issue does not aim to implement optimization over Window 
aggregation.
    
    ## How was this patch tested?
    
    Pass the Jenkins tests (with newly added testcases)


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

    $ git pull https://github.com/dongjoon-hyun/spark SPARK-14664

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

    https://github.com/apache/spark/pull/12421.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 #12421
    
----
commit 48003ee9ab51ae1cbbafbbfb7a30caea2ed51ecc
Author: Dongjoon Hyun <[email protected]>
Date:   2016-04-15T17:56:39Z

    [SPARK-14664][SQL] Fix DecimalAggregates optimizer not to break Window 
queries

----


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