You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/01/05 01:39:19 UTC
[GitHub] [spark] AngersZhuuuu commented on a change in pull request #29087: [SPARK-28227][SQL] Support TRANSFORM with aggregation/window/lateralView
AngersZhuuuu commented on a change in pull request #29087:
URL: https://github.com/apache/spark/pull/29087#discussion_r551668237
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -659,12 +669,39 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
AttributeReference("value", StringType)()), true)
}
+ val namedExpressions = expressions.map {
+ case e: NamedExpression => e
+ case e: Expression => UnresolvedAlias(e)
+ }
+
+ def createProject() = if (namedExpressions.nonEmpty) {
+ Project(namedExpressions, withFilter)
+ } else {
+ withFilter
+ }
+
+ val withProject = if (aggregationClause == null && havingClause != null) {
+ if (conf.getConf(SQLConf.LEGACY_HAVING_WITHOUT_GROUP_BY_AS_WHERE)) {
+ // If the legacy conf is set, treat HAVING without GROUP BY as WHERE.
+ withHavingClause(havingClause, createProject())
+ } else {
+ // According to SQL standard, HAVING without GROUP BY means global aggregate.
+ withHavingClause(havingClause, Aggregate(Nil, namedExpressions, withFilter))
+ }
+ } else if (aggregationClause != null) {
+ val aggregate = withAggregationClause(aggregationClause, namedExpressions, withFilter)
+ aggregate.optionalMap(havingClause)(withHavingClause)
+ } else {
+ // When hitting this branch, `having` must be null.
+ createProject()
+ }
Review comment:
> Is this part just copied from `withSelectQuerySpecification`? If so, could you share it between `withSelectQuerySpecification` and `withTransformQuerySpecification`?
Done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org