[SPARK-57536][SS] Use maxOption instead of sorted.lastOption in HDFSMetadataLog#56596
Open
sarutak wants to merge 1 commit into
Open
[SPARK-57536][SS] Use maxOption instead of sorted.lastOption in HDFSMetadataLog#56596sarutak wants to merge 1 commit into
maxOption instead of sorted.lastOption in HDFSMetadataLog#56596sarutak wants to merge 1 commit into
Conversation
…etadataLog ### What changes were proposed in this pull request? Replace `listBatches.sorted.lastOption` with `listBatches.maxOption` in `HDFSMetadataLog.getLatestBatchId()` and `HDFSMetadataLog.getLatest()`. ### Why are the changes needed? The intent of the code is to find the maximum batch ID. `sorted.lastOption` sorts the entire array in O(n log n) to retrieve only the maximum element, while `maxOption` achieves the same result in O(n). These methods are called on every micro-batch in Structured Streaming, so avoiding unnecessary sorting reduces overhead for long-running streaming jobs with many batches. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? Yes.
dongjoon-hyun
approved these changes
Jun 18, 2026
Member
There was a problem hiding this comment.
+1, LGTM. Good catch. In general, this is not the same because sorted.lastOption is Last Max and maxOption is First Max. However, in this context of Batch Id, it's correct. Thank you, @sarutak .
maxOption instead of sorted.lastOption in HDFSMetadataLog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR replaces
listBatches.sorted.lastOptionwithlistBatches.maxOptioninHDFSMetadataLog.getLatestBatchId()andHDFSMetadataLog.getLatest().Why are the changes needed?
The intent of the code is to find the maximum batch ID.
sorted.lastOptionsorts the entire array in O(n log n) to retrieve only the maximum element, whilemaxOptionachieves the same result in O(n). These methods are called on every micro-batch in Structured Streaming, so avoiding unnecessary sorting reduces overhead for long-running streaming jobs with many batches.Does this PR introduce any user-facing change?
No.
How was this patch tested?
GA
Was this patch authored or co-authored using generative AI tooling?
Kiro CLI / Claude