GitHub user maropu opened a pull request:

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

    [SPARK-18528][SQL] Fix a bug to initialise an iterator of aggregation 
buffer 

    ## What changes were proposed in this pull request?
    This pr is to fix an `NullPointerException` issue caused by a following 
`limit + aggregate` query;
    ```
    scala> val df = Seq(("a", 1), ("b", 2), ("c", 1), ("d", 5)).toDF("id", 
"value")
    scala> df.limit(2).groupBy("id").count().show
    WARN TaskSetManager: Lost task 0.0 in stage 9.0 (TID 8204, 
lvsp20hdn012.stubprod.com): java.lang.NullPointerException
    at 
org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIterator.agg_doAggregateWithKeys$(Unknown
 Source)
    at 
org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIterator.processNext(Unknown
 Source)
    ```
    The root culprit is that 
[`$doAgg()`](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala#L596)
 skips an initialization of [the buffer 
iterator](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala#L603);
 `BaseLimitExec` sets `stopEarly=true` and `$doAgg()` exits in the middle 
without the initialization.
    
    ## How was this patch tested?
    Added a test to check if no exception happens for limit + aggregates in 
`DataFrameAggregateSuite.scala`.


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

    $ git pull https://github.com/maropu/spark SPARK-18528

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

    https://github.com/apache/spark/pull/15980.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 #15980
    
----
commit 31cf318358365fcd237fd9a9ec4f3125996f7e3e
Author: Takeshi YAMAMURO <linguin....@gmail.com>
Date:   2016-11-22T19:18:22Z

    Fix a bug to skip the init of hashmap

----


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