beliefer commented on a change in pull request #29369:
URL: https://github.com/apache/spark/pull/29369#discussion_r468442906
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -339,6 +341,28 @@ object EliminateDistinct extends Rule[LogicalPlan] {
}
}
+/**
+ * Remove useless FILTER clause for aggregate expressions.
+ * This rule should be applied before RewriteDistinctAggregates.
+ */
+object EliminateAggregateFilter extends Rule[LogicalPlan] {
+ override def apply(plan: LogicalPlan): LogicalPlan = plan
transformExpressions {
+ case ae @ AggregateExpression(_, _, _, Some(Literal.TrueLiteral), _) =>
+ ae.copy(filter = None)
+ case AggregateExpression(af: DeclarativeAggregate, _, _,
Some(Literal.FalseLiteral), _) =>
+ val initializer = SafeProjection.create(af.initialValues)
+ val evaluator = SafeProjection.create(af.evaluateExpression :: Nil,
af.aggBufferAttributes)
+ val buffer = new
SpecificInternalRow(af.aggBufferAttributes.map(_.dataType))
+ val initBuffer = initializer(buffer).copy()
Review comment:
no need copy.
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]