zml1206 commented on code in PR #57815:
URL: https://github.com/apache/spark/pull/57815#discussion_r3763007976
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowEvaluatorFactoryBase.scala:
##########
@@ -219,13 +236,70 @@ trait WindowEvaluatorFactoryBase {
MutableProjection.create(expressions, schema),
aggFilters)
}
+ lazy val distinctAggregateExpressions =
+ functions.map(_.asInstanceOf[AggregateExpression])
+ lazy val originalDistinctExpressions =
+ distinctChildren(distinctAggregateExpressions.head)
+ lazy val normalizedDistinctExpressions =
+ originalDistinctExpressions.map(NormalizeFloatingNumbers.normalize)
+ lazy val distinctInputAttributes =
+ normalizedDistinctExpressions.zipWithIndex.map { case (expression,
index) =>
+ AttributeReference(
+ s"windowDistinctValue$index",
+ expression.dataType,
+ expression.nullable)()
+ }
+ lazy val rewrittenDistinctFunctions: Array[Expression] =
+ distinctAggregateExpressions.map { ae =>
+ val distinctColumnAttributeLookup = Utils.toMap(
+ distinctChildren(ae).map(_.canonicalized),
+ distinctInputAttributes)
+ ae.aggregateFunction.transformDown {
+ case expression: Expression
+ if
distinctColumnAttributeLookup.contains(expression.canonicalized) =>
+ distinctColumnAttributeLookup(expression.canonicalized)
Review Comment:
Fixed. The transform callback now canonicalizes each visited expression once
and uses a single getOrElse lookup.
--
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]