Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/5604#discussion_r29013060
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala ---
@@ -736,32 +741,36 @@
https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
// The projection of the query can either be a normal projection,
an aggregation
// (if there is a group by) or a script transformation.
val withProject: LogicalPlan = transformation.getOrElse {
- val selectExpressions =
+ val selectExpressions =
nameExpressions(select.getChildren.flatMap(selExprNodeToExpr).toSeq)
- Seq(
- groupByClause.map(e => e match {
- case Token("TOK_GROUPBY", children) =>
- // Not a transformation so must be either project or
aggregation.
- Aggregate(children.map(nodeToExpr), selectExpressions,
withLateralView)
- case _ => sys.error("Expect GROUP BY")
- }),
- groupingSetsClause.map(e => e match {
- case Token("TOK_GROUPING_SETS", children) =>
- val(groupByExprs, masks) = extractGroupingSet(children)
- GroupingSets(masks, groupByExprs, withLateralView,
selectExpressions)
- case _ => sys.error("Expect GROUPING SETS")
- }),
- rollupGroupByClause.map(e => e match {
- case Token("TOK_ROLLUP_GROUPBY", children) =>
- Rollup(children.map(nodeToExpr), withLateralView,
selectExpressions)
- case _ => sys.error("Expect WITH ROLLUP")
- }),
- cubeGroupByClause.map(e => e match {
- case Token("TOK_CUBE_GROUPBY", children) =>
- Cube(children.map(nodeToExpr), withLateralView,
selectExpressions)
- case _ => sys.error("Expect WITH CUBE")
- }),
- Some(Project(selectExpressions, withLateralView))).flatten.head
+
+ val groupPlan = (selectExprs: Seq[NamedExpression]) =>
+ Seq(
+ groupByClause.map(e => e match {
+ case Token("TOK_GROUPBY", children) =>
+ // Not a transformation so must be either project or
aggregation.
+ Aggregate(children.map(nodeToExpr), selectExprs,
withLateralView)
+ case _ => sys.error("Expect GROUP BY")
+ }),
--- End diff --
Actually you can simplify this to:
```scala
groupByClause.map {
case Token("TOK_GROUPBY", children) =>
...
case _ => ...
}
```
Also applies to other parts below.
---
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]