LukaZdravic opened a new pull request, #60798: URL: https://github.com/apache/spark/pull/60798
### What changes were proposed in this pull request? `AsOfJoin.makeAsOfCond` no longer makes the tolerance bound strict when `allowExactMatches = false`. `allowExactMatches` now changes only the match itself (`>` instead of `>=`, `<` instead of `<=`, and `l <> r` for nearest). The tolerance bound stays `>=` / `<=` for backward, forward and nearest. Both engines share this condition (the old rewrite and the sort-merge operator), so both change. A line in `docs/sql-migration-guide.md` describes the change. ### Why are the changes needed? A right row that is exactly `tolerance` away was dropped only when `allowExactMatches = false`. SQL `ASOF JOIN` and pandas `merge_asof` (for exact key types) keep it. ``` left 5, right 3, tolerance 2, backward, allowExactMatches = false SQL: MATCH_CONDITION (l.t > r.t) ON r.t >= l.t - 2 -> keeps 3 pandas merge_asof(tolerance=2, allow_exact_matches=False) -> keeps 3 DataFrame joinAsOf, before this PR -> no row ``` ### Does this PR introduce _any_ user-facing change? Yes. `pyspark.pandas.merge_asof` (and the internal DataFrame as-of join under it) with `tolerance` and `allow_exact_matches=False` now keeps a right row exactly `tolerance` away. Before, that row was dropped. There is no switch for the old result. Known difference: on an equal-distance tie, nearest with the old rewrite picks any one row. Now a tie can also happen with one row on each bound. Not changed here. ### How was this patch tested? - `DataFrameAsOfJoinSuite`: new tests for backward, forward and nearest with INT, DATE and TIMESTAMP keys. Each runs with the sort-merge flag off and on (and the single-pass analyzer with it on), ANSI off and on, `allowExactMatches` off and on. They check rows on the bound (kept), one past the bound (dropped) and an exact match (still dropped for backward and forward). - `RewriteAsOfJoinSuite`: the three tolerance + `allowExactMatches = false` plan tests now expect `>=` / `<=`. - `SortMergeAsOfJoinSuite`: the "boundary" case of the interval tolerance test now expects a match. - `test_merge_asof.py`: new test compares `ps.merge_asof` with `pd.merge_asof` on the bound, all directions. Not run here (no pandas). - Also ran `AsOfJoinSQLSuite`, `AsOfJoinSortMergeSQLSuite`, `SortMergeAsOfJoinScannerSuite`, `StreamingAsOfJoinSuite`, `FilterPushdownSuite`, `InferFiltersFromConstraintsSuite`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code This pull request and its description were written by Isaac. -- 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]
