Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/11283#discussion_r54821287
--- Diff:
sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
@@ -211,6 +215,71 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext:
SQLContext) extends Loggi
)
}
+ private def groupingSetToSQL(
+ plan: Aggregate,
+ expand: Expand,
+ project: Project): String = {
+ // In cube/rollup/groupingsets, Analyzer creates new aliases for all
group by expressions.
+ // Since conversion from attribute back SQL ignore expression IDs, the
alias of attribute
+ // references are ignored in aliasMap
+ val aliasMap = AttributeMap(project.projectList.collect {
+ case a @ Alias(child, name) if
!child.isInstanceOf[AttributeReference] => (a.toAttribute, a)
+ })
+
+ val groupingExprs = plan.groupingExpressions.filterNot {
+ // VirtualColumn.groupingIdName is added by Analyzer, and thus
remove it.
+ case a: NamedExpression => a.name == VirtualColumn.groupingIdName
+ case o => false
+ }.map {
+ case a: AttributeReference if aliasMap.contains(a) =>
aliasMap(a).child
+ case o => o
+ }
+
--- End diff --
I think the `groupingExpressions` must be all `Attribute`, see
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L302-L305
. Did I miss something here?
---
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]