cloud-fan commented on a change in pull request #29369:
URL: https://github.com/apache/spark/pull/29369#discussion_r467664263



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -339,6 +340,39 @@ 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 ae @ AggregateExpression(af, _, _, Some(Literal.FalseLiteral), _) =>
+      rewrite(ae, af)
+    case ae @ AggregateExpression(af, _, _, Some(e), _)

Review comment:
       We don't need to handle this. We should assume `ConstantFolding` will 
take care of it.




----------------------------------------------------------------
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]

Reply via email to