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

    https://github.com/apache/spark/pull/5134#discussion_r29218551
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -115,6 +115,25 @@ object UnionPushdown extends Rule[LogicalPlan] {
      */
     object ColumnPruning extends Rule[LogicalPlan] {
       def apply(plan: LogicalPlan): LogicalPlan = plan transform {
    +    // Eliminate unneeded attributes from Expand that is used in 
GroupingSets
    +    case a @ Aggregate(groupByExprs, aggregations, e @ Expand(projections, 
output, child))
    +        if (e.outputSet -- a.references).nonEmpty =>
    +
    +      val substitution = projections.map { groupExpr =>
    --- End diff --
    
    In `Analyzer.ResolveGroupingAnalytics`, the projections of `Expand` node 
contain some `Literal`s that are constant null. Also the `groupingId` will be 
replaced with concrete value (the bit mask). We need to keep these `Literal`s.
    
    Because it performs `collect` on the `groupExpr: Seq[Expression]`, it just 
keeps all `Literal`s and the `NamedExpression`s which are refered in `a: 
Aggregate`.
    
    So we do:
    
        GroupExpression(a + 1, b, 1) => GroupExpression(a + 1, 1)  # suppose 
that b is not referred in above Aggregate
    



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