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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -3587,8 +3600,9 @@ object PushPredicateThroughJoin extends Rule[LogicalPlan] 
with PredicateHelper {
 
     // Left-side WHERE predicate can run before the ASOF join, but a 
right-side one cannot
     case f @ Filter(filterCondition, j: AsOfJoin) =>
-      val (leftFilterConditions, rightFilterConditions, commonFilterCondition) 
=
-        split(splitConjunctivePredicates(filterCondition), j.left, j.right)
+      val (leftFilterConditions, rightFilterConditions, commonFilterCondition) 
= split(
+        splitConjunctivePredicates(filterCondition), j.left, j.right,
+        hasBarrier(j.joinType, j.condition))

Review Comment:
   Thank you for the review. You are right. `SortMergeAsOfJoinExec` evaluates 
the `ON` condition only on the pairs that pass the as-of comparison, so a 
throwable `MATCH_CONDITION` operand or as-of key decides which left rows reach 
the filter, as a throwable `ON` conjunct does. Your query, the guard in the 
left operand, and a DataFrame nearest join with a guarded left key all failed 
with `DIVIDE_BY_ZERO` at 91a009973d9.
   
   The same comparison also guards the `ON` conjuncts, so the `AsOfJoin` case 
that pushes them into the inputs had the same problem: with your guard, `ON a.k 
= b.k AND 10 / (a.v - 9) < 100` failed too, and so did a `LEFT ASOF JOIN` with 
`10 / (b.g - 9) < 100` over the right side. I fixed both:
   
   - `hasBarrier` takes the conditions, and the `Filter` over `AsOfJoin` case 
passes `asOfMatchExpressions(j) ++ j.condition`. `asOfMatchExpressions` is the 
as-of condition and the sort keys, which hold the keys of a nearest join whose 
as-of condition is `true`.
   - The `AsOfJoin` case sets `afterBarrier` when `asOfMatchExpressions` has a 
non-deterministic or throwable expression, for both join types, since a left 
outer join does not keep every right row.
   - `FilterPushdownSuite` has a plan test with a nearest join whose left key 
is throwable, and `AsOfJoinSortMergeSQLSuite` runs a `MATCH_CONDITION` guard 
with a division in `WHERE`, in `ON` over the left side, and in `ON` over the 
right side of a `LEFT ASOF JOIN`.
   
   I also updated the PR description.
   



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