beam icon indicating copy to clipboard operation
beam copied to clipboard

[Spark] SparkStateInternals: MapState and SetState isEmpty() stays false after removing the last element

Open tkaymak opened this issue 2 months ago • 6 comments

SparkStateInternals backs MapState and SetState with one coded cell per state. remove() writes the shrunk collection back even when it is now empty, see SparkStateInternals.java lines 432 to 436 (map) and 537 to 541 (set). isEmpty() only checks whether the cell exists (lines 501 and 560), so it returns false after the last element is removed. InMemoryStateInternals returns true in that case.

The shared StateInternalsTest does not catch this, because it checks isEmpty() only after clear().

Side effect: SparkGroupAlsoByWindowViaWindowSet keeps a key's state as long as getState() is not empty (lines 265 and 307). A key whose map or set was emptied by removals is therefore kept instead of dropped.

Fix: when the collection becomes empty, call clear() instead of writing it back. Add one test to StateInternalsTest for isEmpty after removing the last map and set element.

Line numbers refer to master 00e322188bf. Found while working on #36841.

tkaymak avatar Sep 24 '26 16:09 tkaymak

Hi, I'd like to work on this issue. I’ll investigate the SparkStateInternals implementation and add the corresponding tests for MapState and SetState. Could you assign this issue to me?

aryan9948 avatar Sep 24 '26 19:09 aryan9948

Hi!, I would like to work on this issue if this issue is not assigned yet.

schizophrenicmaniac avatar Sep 28 '26 05:09 schizophrenicmaniac

Hi, is the issue still open, I would like to work on it.

dhruv-dagar avatar Oct 04 '26 03:10 dhruv-dagar

/assign

dhruv-dagar avatar Oct 04 '26 03:10 dhruv-dagar

.take-issue

parvarh26 avatar Oct 05 '26 05:10 parvarh26

.free-issue

parvarh26 avatar Oct 05 '26 05:10 parvarh26