dongjoon-hyun commented on code in PR #60765:
URL: https://github.com/apache/spark/pull/60765#discussion_r4651115783


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -3115,14 +3115,16 @@ object PushPredicateThroughNonJoin extends 
Rule[LogicalPlan] with PredicateHelpe
   private def pushDownPredicate(
       filter: Filter,
       grandchild: LogicalPlan,
-      keepThrowableUp: Boolean)(insertFilter: Expression => LogicalPlan): 
LogicalPlan = {
+      keepFailableUp: Boolean)(insertFilter: Expression => LogicalPlan): 
LogicalPlan = {
     // Only push down the predicates that is deterministic and all the 
referenced attributes
-    // come from grandchild. With `keepThrowableUp`, a throwable predicate is 
not pushed even when
-    // it is written first, as the operator in between can drop rows it would 
then see.
+    // come from grandchild. With `keepFailableUp`, a predicate that can fail, 
i.e. one that
+    // `ExprUtils.canEvaluateUnconditionally` rejects such as a throwable one 
or an ANSI division,
+    // is not pushed even when it is written first, as the operator in between 
can drop rows it
+    // would then see.
     // TODO: non-deterministic predicates could be pushed through some 
operators that do not change
     // the rows.
     val (pushDown, stayUp) = splitPushableConjuncts(filter.condition) { cond =>
-      cond.deterministic && !(keepThrowableUp && cond.throwable) &&
+      cond.deterministic && (!keepFailableUp || 
ExprUtils.canEvaluateUnconditionally(cond)) &&

Review Comment:
   Update: I added an internal legacy conf after all, 
`spark.sql.legacy.pushFailableFiltersThroughGenerate` (default `false`). Unlike 
the other filter pushdown fixes for conditions that can fail, which only apply 
after a non-deterministic or throwable condition, this change applies to every 
filter above a generator without `OUTER` or a `TRANSFORM` script, like the 
change for inferred filters, which added 
`spark.sql.legacy.inferFailableFiltersFromConstraints`. When it is `true`, only 
a throwable condition stays above these operators, as before this PR. The 
migration guide entry names it, and a `FilterPushdownSuite` test covers 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.

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]

Reply via email to