Skip to content

Commit e591f9f

Browse files
committed
Update AstBuilder.scala
1 parent ea7188d commit e591f9f

File tree

1 file changed

+5
-15
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser

1 file changed

+5
-15
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -623,20 +623,6 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
623623
UnresolvedHaving(predicate, plan)
624624
}
625625

626-
/**
627-
* Create a logical plan treat having as where when without GROUP BY
628-
*/
629-
private def withHavingClauseAsWhere(
630-
ctx: HavingClauseContext, plan: LogicalPlan): LogicalPlan = {
631-
// Note that we add a cast to non-predicate expressions. If the expression itself is
632-
// already boolean, the optimizer will get rid of the unnecessary cast.
633-
val predicate = expression(ctx.booleanExpression) match {
634-
case p: Predicate => p
635-
case e => Cast(e, BooleanType)
636-
}
637-
Filter(predicate, plan)
638-
}
639-
640626
/**
641627
* Create a logical plan using a where clause.
642628
*/
@@ -728,7 +714,11 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
728714
val withProject = if (aggregationClause == null && havingClause != null) {
729715
if (conf.getConf(SQLConf.LEGACY_HAVING_WITHOUT_GROUP_BY_AS_WHERE)) {
730716
// If the legacy conf is set, treat HAVING without GROUP BY as WHERE.
731-
withHavingClauseAsWhere(havingClause, createProject())
717+
val predicate = expression(havingClause.booleanExpression) match {
718+
case p: Predicate => p
719+
case e => Cast(e, BooleanType)
720+
}
721+
Filter(predicate, createProject())
732722
} else {
733723
// According to SQL standard, HAVING without GROUP BY means global aggregate.
734724
withHavingClause(havingClause, Aggregate(Nil, namedExpressions, withFilter))

0 commit comments

Comments
 (0)