LukaZdravic opened a new pull request, #60239:
URL: https://github.com/apache/spark/pull/60239
### What changes were proposed in this pull request?
`SortMergeAsOfJoinScanner` compares left and right ON keys with one
ordering, which it built from the nullability of the left keys only. For a NOT
NULL left key, that ordering skips the NULL check, but the right key it
compares can still be NULL. This PR builds the ordering with
`RowOrdering.createNaturalAscendingOrdering`, which treats every key as
nullable, as the sort-merge join does.
### Why are the changes needed?
A NULL right key compared as its empty value, for example 0 for an INT key.
So it could match a left key of 0, and a left key could miss its match because
the scan stopped at the NULL row. STRING and DECIMAL keys failed with a
NullPointerException.
### Does this PR introduce _any_ user-facing change?
Yes, it fixes wrong results:
```sql
SELECT t.k, q.tag FROM VALUES (-1, 10), (0, 10) AS t(k, ts)
LEFT ASOF JOIN VALUES (CAST(NULL AS INT), 1, 'null key'), (-1, 2, 'minus
one') AS q(k, ts, tag)
MATCH_CONDITION (t.ts >= q.ts) ON t.k = q.k
-- before: (-1, NULL), (0, 'null key')
-- after: (-1, 'minus one'), (0, NULL)
```
### How was this patch tested?
New `AsOfJoinSortMergeSQLSuite` tests join a NOT NULL left key against a
NULL right key for INT, STRING and DECIMAL keys and for the second of two ON
keys, with the cursor scan off and on. A new `SortMergeAsOfJoinSuite` test does
the same for a nearest join. The randomized comparison with a plain join now
uses a NOT NULL left key for one seed. Without the fix, these 6 tests fail. The
ASOF join suites, `PlannerSuite` and `SQLMetricsSuite` pass.
### 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]