LukaZdravic opened a new pull request, #60240:
URL: https://github.com/apache/spark/pull/60240

   ### What changes were proposed in this pull request?
   `findLastBackward`, `findFirstForward` and `findNearest` in 
`SortMergeAsOfJoinScanner` make a new iterator over the right-side group for 
each left row, and usually return before it ends. Once the group has spilled, 
that iterator holds a reader open on every spill file until it ends or is 
closed. This PR closes the iterator in a `finally` block. A match the scan 
keeps is already a copy once the group has spilled, so closing the iterator 
does not change it.
   
   The fix uses the `close()` that SPARK-58201 added to the spill iterator of 
`ExternalAppendOnlyUnsafeRowArray`. That change is only on master, so a 
backport to branch-4.x needs it too. Without it, the code compiles but closes 
nothing, and the new test fails.
   
   ### Why are the changes needed?
   The open files stayed open until the task ended. With L left rows in a group 
spilled to S files, a task kept up to L * S files open, which can fail it with 
"Too many open files". Each reader's 1 MB heap buffer still stays until the 
task ends, because a task-completion listener keeps the reader. This PR does 
not change that.
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   ### How was this patch tested?
   A new `SortMergeAsOfJoinScannerSuite` test runs a backward, a forward and a 
nearest buffered scan, each in its own task, of 16 left rows over a 50-row 
right group that spills every 10 rows. It checks the matched rows, and that the 
JVM's open file count does not grow with the left rows. Without the fix, each 
scan left 55 or 56 more files open. With it, none. 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]

Reply via email to