cloud-fan commented on code in PR #46143:
URL: https://github.com/apache/spark/pull/46143#discussion_r2828758300
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AliasHelper.scala:
##########
@@ -65,6 +65,30 @@ trait AliasHelper {
})
}
+ /**
+ * Replace all attributes, that reference an alias, with the aliased
expression.
+ * Tracks which aliases were replaced and returns them.
+ */
+ protected def replaceAliasWhileTracking(
+ expr: Expression,
+ aliasMap: AttributeMap[Alias]): (Expression, AttributeMap[Alias]) = {
+ // Use transformUp to prevent infinite recursion when the replacement
expression
+ // redefines the same ExprId,
+ var replaced = AttributeMap.empty[Alias]
+ val newExpr = trimAliases(expr.transformUp {
+ case a: Attribute =>
+ // If we replace an alias add it to replaced
+ val newElem = aliasMap.get(a)
+ newElem match {
+ case None => a
+ case Some(b) =>
+ replaced += (a, b)
Review Comment:
we should skip this operation if the AttributeMap already contains `a`. It
does not change the result but is more efficient.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]