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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2871,10 +2871,13 @@ object PushPredicateThroughNonJoin extends 
Rule[LogicalPlan] with PredicateHelpe
         // split orders conditions by cost, and cost is no way to decide how 
many rows a
         // non-deterministic expression sees. Throwable conditions, or 
conditions over throwable
         // aliases, stay there too: ordering by cost could evaluate them (or 
compute the aliases
-        // in a lower projection) ahead of the conditions written before them.
+        // in a lower projection) ahead of the conditions written before them. 
So do all the
+        // conditions written after the first of these: each reads an 
expensive alias, e.g. a UDF
+        // or a regex whose pattern comes from the data, which can fail, so a 
lower layer must
+        // not evaluate it on the rows that condition filters out.
         val (splitChild, splitAliases, stayUp) =
           if (expensiveWithUsed.nonEmpty && 
SQLConf.get.splitProjectionForExpensiveFilters) {
-            val (splittable, notSplittable) = expensiveWithUsed.partition {
+            val (splittable, notSplittable) = expensiveWithUsed.span {

Review Comment:
   Update: I fixed it in this PR instead of waiting for #60766. The split now 
leaves at least one expensive alias of each condition written after the 
non-deterministic or throwable one to the top projection, so the next pass 
still sees that condition as expensive and keeps it above. Both of your queries 
now return 9 rows in ANSI mode with whole-stage codegen on and off, with or 
without #60766. I added the first one to the `DataFrameSuite` test, and a plan 
test for the split.
   



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