Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11283#discussion_r54982167
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -233,6 +242,72 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: 
SQLContext) extends Loggi
         )
       }
     
    +  private def groupingSetToSQL(
    +      agg: Aggregate,
    +      expand: Expand,
    +      project: Project): String = {
    +    assert(agg.groupingExpressions.length > 1)
    +
    +    // The last column of Expand is always grouping ID
    +    val gid = expand.output.last
    +
    +    val numOriginalOutput = project.child.output.length
    +    // Assumption: Aggregate's groupingExpressions is composed of
    +    // 1) the group by attributes' aliases
    +    // 2) gid, which is always the last one
    +    val groupByAttributes = 
agg.groupingExpressions.dropRight(1).map(_.asInstanceOf[Attribute])
    +    // Assumption: Project's projectList is composed of
    +    // 1) the original output (Project's child.output),
    +    // 2) the aliases of the original group by attributes, which could be 
expressions
    +    val groupByExprs = 
project.projectList.drop(numOriginalOutput).map(_.asInstanceOf[Alias].child)
    +    val groupingSQL = groupByExprs.map(_.sql).mkString(", ")
    +
    +    // a map from the alias name to the original group by 
expresions/attributes
    --- End diff --
    
    update this comment: `a map from group by attributes to the original group 
by expressions.`


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