spark-test commented on code in PR #60411:
URL: https://github.com/apache/spark/pull/60411#discussion_r4557650883
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/SortMergeAsOfJoinExec.scala:
##########
@@ -821,11 +824,14 @@ private[joins] class SortMergeAsOfJoinScanner(
}
/**
- * Backward joins keep the last row that passes the as-of and residual
conditions.
- * Once the as-of condition has been true, the scan stops at the first row
that fails
- * it, as later sorted rows cannot satisfy it.
+ * Backward and forward joins scan the group in as-of key order for the row
that passes the
+ * as-of and residual conditions and is closest to the left key: the first
passing row or the
+ * last, as [[AsOfScanStrategy.firstMatchWins]] tells. Once the as-of
condition has been true,
+ * the scan stops at the first row that fails it, as later sorted rows
cannot satisfy it. That
+ * row is past the left key for a backward join, and past the tolerance for
a forward join.
Review Comment:
**Nit (P3):** With `allowExactMatches = false`, `AsOfJoin.makeAsOfCond`
builds strict conditions (`left.t > right.t` for backward, `left.t < right.t`
for forward, and strict tolerance bounds), so the row that ends this scan can
have exactly the left key, or sit exactly on the tolerance bound, instead of
lying past it. Following the code for a backward join with left key 5 and right
keys 2, 5, 7, `findInOrder` keeps 2 and stops at the row with key 5, which is
at the left key. The scan's decision is right, so no result changes; only the
stated position misses the tie, which the removed `findLastBackward` comment
covered with "At or past left.t". A later change that trusts this wording could
assume that a right row at the left key always passes.
The `AsOfScanStrategy.matchOutlivesLeftRow` doc (lines 1115-1116) has the
same gap for the cursor scan, which `supportsCursorScan` also allows with `>`
and `<`: the backward cursor stops at a right row whose key equals the left key
and keeps it for the next left row, and the forward cursor drops such a row, so
"at or ahead of the left key" and "at or behind the left key" would be accurate
there. The forward "past the tolerance" half of this line repeats the base
branch's "Past the tolerance bound" wording, but the same tie applies, so the
suggestion covers it too:
```suggestion
* row is at or past the left key for a backward join, and at or past the
tolerance bound for a
* forward join.
```
**Verification:**
- **Inspection:** Read the two rewritten comments against the as-of
conditions the scans admit, including the strict comparisons and strict
tolerance bounds used when exact matches are disallowed, and confirm that each
stated position still holds when a right row's as-of key equals the left key or
sits exactly on the tolerance bound.
- **Inspection:** Confirm that the change touches only comment text, so the
scans and the Java they generate are unchanged.
--
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]