Github user xwu0226 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12974#discussion_r62789705
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/PlannerSuite.scala ---
    @@ -44,10 +44,12 @@ class PlannerSuite extends SharedSQLContext {
             fail(s"Could query play aggregation query $query. Is it an 
aggregation query?"))
         val aggregations = planned.collect { case n if n.nodeName contains 
"Aggregate" => n }
     
    -    // For the new aggregation code path, there will be four aggregate 
operator for
    -    // distinct aggregations.
    +    // For the new aggregation code path, there will be three aggregate 
operator for
    +    // distinct aggregations. There used to be four aggregate operators 
because single
    +    // distinct aggregate used to trigger DistinctAggregationRewriter 
rewrite. Now the
    +    // the rewrite only happens when there are multiple distinct 
aggregations.
         assert(
    -      aggregations.size == 2 || aggregations.size == 4,
    +      aggregations.size == 2 || aggregations.size == 3,
    --- End diff --
    
    Before my change of moving the `DistinctAggregationRewriter` rule to 
Optimizer, Analyzer resolved the single distinct case into 2-layered 
non-distinct Aggregates and an EXPAND as following:
    ```
    Aggregate [value#3], [value#3,(count(if ((gid#48 = 1)) key#49 else 
null),mode=Complete,isDistinct=false) AS count(key)#47L]
    +- Aggregate [value#3,key#49,gid#48], [value#3,key#49,gid#48]
       +- Expand [ArrayBuffer(value#3, key#2, 1)], [value#3,key#49,gid#48]
          +- LogicalRDD [key#2,value#3], MapPartitionsRDD[3] at beforeAll at 
BeforeAndAfterAll.scala:187
    ```
    Then, the resulted physical Plan in this testcase had 4 `TungstenAggregate` 
generated by 
[aggregate/utils.planAggregateWithoutDistinct](https://github.com/apache/spark/blob/branch-1.6/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/utils.scala#L65-L131).
 So this testcase checked for 4 aggregations. 
    
    After my change, there is no rewrite for the single distinct aggregate 
anymore, the analyzed plan looks like this:
    ```
    Aggregate [value#3], [value#3,(count(key#2),mode=Complete,isDistinct=true) 
AS count(key)#47L]
    +- LogicalRDD [key#2,value#3], MapPartitionsRDD[3] at beforeAll at 
BeforeAndAfterAll.scala:187
    ```
    Then, the physical plan are resulted in 3 `TungstenAggregate` by 
[aggregate/utils.planAggregateWithOneDistinct](https://github.com/apache/spark/blob/branch-1.6/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/utils.scala#L160-L288)
    
    Therefore, I need to modify this testcase. 


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