Commit 7753a7d
[SPARK-55271][SS] Fix NullPointerException in Kafka micro-batch streaming metrics reporting
### What changes were proposed in this pull request?
This PR fixes a `NullPointerException` in `KafkaMicroBatchStream.metrics()` during Kafka micro-batch streaming progress reporting (`finishTrigger`).
Specifically, `KafkaMicroBatchStream.metrics()` checked `latestAvailablePartitionOffsets.isDefined` before extracting partition offsets. If `latestAvailablePartitionOffsets` was `Some(null)`, `isDefined` returned `true`, causing `latestAvailablePartitionOffsets.get` to return `null` and throwing a `NullPointerException` when `.map()` was invoked on it.
This PR updates the condition to `latestAvailablePartitionOffsets.exists(_ != null)` to safely ensure partition offsets are non-null before invoking `.map()`.
### Why are the changes needed?
When uninitialized partition offsets or race conditions occur during progress reporting (`finishTrigger`), `latestAvailablePartitionOffsets` can be `Some(null)`. Without this check, calling `.map()` on `null` throws a `NullPointerException`, crashing the entire streaming query job in production after batch execution.
### Does this PR introduce _any_ user-facing change?
No API changes. Fixes a `NullPointerException` in progress reporting metrics.
### How was this patch tested?
Added unit test assertion in `KafkaMicroBatchSourceSuite`.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #58133 from zahed1994/SPARK-55271-kafka-streaming-metrics-npe.
Authored-by: zahed1994 <zahedshareef@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 3a9f11f)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>1 parent 993357d commit 7753a7d
2 files changed
Lines changed: 3 additions & 1 deletion
File tree
- connector/kafka-0-10-sql/src
- main/scala/org/apache/spark/sql/kafka010
- test/scala/org/apache/spark/sql/kafka010
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
| 517 | + | |
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1852 | 1852 | | |
1853 | 1853 | | |
1854 | 1854 | | |
| 1855 | + | |
| 1856 | + | |
1855 | 1857 | | |
1856 | 1858 | | |
1857 | 1859 | | |
| |||
0 commit comments