tgravescs commented on a change in pull request #30504:
URL: https://github.com/apache/spark/pull/30504#discussion_r531707264



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -873,24 +873,30 @@ object InferFiltersFromGenerate extends Rule[LogicalPlan] 
{
       if !e.deterministic || e.children.forall(_.foldable) => generate
 
     case generate @ Generate(g, _, false, _, _, _) if canInferFilters(g) =>
-      // Exclude child's constraints to guarantee idempotency
-      val inferredFilters = ExpressionSet(
-        Seq(
-          GreaterThan(Size(g.children.head), Literal(0)),
-          IsNotNull(g.children.head)
-        )
-      ) -- generate.child.constraints
-
-      if (inferredFilters.nonEmpty) {
-        generate.copy(child = Filter(inferredFilters.reduce(And), 
generate.child))
-      } else {
-        generate
+      g.children.head match {
+        case _: CreateNonEmptyNonNullCollection =>
+          // we don't need to add filters when creating an array because we 
know its size
+          // is > 0 and its not null
+          generate
+        case _ =>
+          // Exclude child's constraints to guarantee idempotency
+          val inferredFilters = ExpressionSet(
+            Seq(
+              GreaterThan(Size(g.children.head), Literal(0)),
+              IsNotNull(g.children.head)

Review comment:
       thanks for explaining. I'm new to optimizer code. The problem here is 
that the size is only 0 in this context because otherwise it would be foldable 
and hit the case statement above.  Since the SimplifyBinaryCompare check is 
totally separate, is it safe to assume anything with type 
CreateNonNullCollection then size == 0 can be removed? It definitely applies 
here, but for instance if someone else adds a separate optimizer rule in the 
future.  If you think that is ok I can add it there instead?  Let me know what 
you think
   




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to