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

   ### What changes were proposed in this pull request?
   
   This PR fixes a `NullPointerException` in `InMemoryStore.count(Class, 
String, Object)` and makes its behavior consistent with the other `KVStore` 
implementations.
   
   `inMemoryLists.get(type)` returns `null` for a type that has never been 
written, and the method then dereferenced it via 
`list.getIndexAccessor(index)`, throwing an NPE. The fix adds an early branch 
for the never-written type that returns `0`. It still validates the index name 
first (via a `KVTypeInfo` built from the type, mirroring how 
`LevelDB`/`RocksDB` lazily build their type info), so an unknown index name 
throws `IllegalArgumentException` exactly as it does for a populated type and 
for the `LevelDB`/`RocksDB` stores, rather than being silently swallowed into a 
`0`.
   
   ### Why are the changes needed?
   
   It is a bug: counting by an indexed value for a type with no instances 
should return `0`, not throw. The sibling one-arg `count(Class)` already 
returns `0` in this situation, and both `LevelDB.count` and `RocksDB.count` 
return `0` for an absent type, so `InMemoryStore` was inconsistent with its 
siblings. The 3-arg `count` was also previously uncovered by 
`InMemoryStoreSuite`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Added `InMemoryStoreSuite.testCountByIndexValue`, which covers an absent 
type returning `0`, an unknown index name throwing `IllegalArgumentException` 
for both the absent-type and populated-type paths, and the match-counting cases 
for a populated type. Ran `build/sbt 'kvstore/testOnly *InMemoryStoreSuite'` 
and all tests pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


-- 
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