LukaZdravic opened a new pull request, #60227: URL: https://github.com/apache/spark/pull/60227
### What changes were proposed in this pull request? `SortMergeAsOfJoinExec` gets whole-stage codegen for backward and forward joins. The generated code runs the same two scans as `SortMergeAsOfJoinScanner`: the cursor scan, and the buffered scan of each right-side group. It compares the ON keys, checks the MATCH_CONDITION and the residual ON condition inline, and passes the output columns straight to the parent. - The right-side buffer stays an `ExternalAppendOnlyUnsafeRowArray`, which can spill, as in `SortMergeJoinExec`. Nearest joins keep the interpreted scan. - The join's children get their own codegen stages, and `UnionExec.isKnownMultiInputRDDCodegen` lists the join, as it lists `SortMergeJoinExec`. - `createJoinKey`, `copyKeys` and `genComparison` move unchanged from `SortMergeJoinExec` to `JoinCodegenSupport`. - The new internal config `spark.sql.codegen.join.sortMergeAsOfJoin.enabled` (default `true`) turns it off. ### Why are the changes needed? The interpreted scan pays general costs on every row, and the join ends the codegen stage above it, so each output row is built and handed over one by one. ### Does this PR introduce _any_ user-facing change? No. The join returns the same rows and raises the same errors. Only the speed changes. ### How was this patch tested? Every check in `AsOfJoinSortMergeSQLSuite` now runs with this codegen off and on, and asserts which joins were generated. The spill tests in `SortMergeAsOfJoinSuite` do the same. New tests: a NULL right ON key, a collated ON key, a `WholeStageCodegenSuite` case (backward, forward, LEFT OUTER, tolerance, nearest, config off), and a `UnionCodegenSuite` case that failed with "child Project returned 2 RDDs" before the union change. The `join-asof-*.sql` golden files that run joins now use the codegen `CONFIG_DIM1`, like `inner-join.sql`. Removing the cursor's empty-group check, its best-row copy, its group reset, or the NULL right-key compare fails at least one of these tests. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code -- 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]
