Skip to content

Commit 0ae48d8

Browse files
committed
Put strick checker
1 parent 86402b0 commit 0ae48d8

File tree

1 file changed

+5
-1
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis

1 file changed

+5
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,12 @@ class Analyzer(
10071007
case agg @ Aggregate(groups, aggs, child)
10081008
if conf.groupByAliases && child.resolved && aggs.forall(_.resolved) &&
10091009
groups.exists(_.isInstanceOf[UnresolvedAttribute]) =>
1010+
// This is a strict check though, we put this to apply the rule only in alias expressions
1011+
def checkIfChildOutputHasNo(attrName: String): Boolean =
1012+
!child.output.exists(a => resolver(a.name, attrName))
10101013
agg.copy(groupingExpressions = groups.map {
1011-
case u: UnresolvedAttribute => aggs.find(ne => resolver(ne.name, u.name)).getOrElse(u)
1014+
case u: UnresolvedAttribute if checkIfChildOutputHasNo(u.name) =>
1015+
aggs.find(ne => resolver(ne.name, u.name)).getOrElse(u)
10121016
case e => e
10131017
})
10141018
}

0 commit comments

Comments
 (0)