cshuo opened a new issue, #20435:
URL: https://github.com/apache/hudi/issues/20435

   ### Description
   
   Partitioned record-level index (RLI) point lookups can throw exceptions when 
querying an empty partition or passing an empty key collection.
   
   In `HoodieBackedTableMetadata.lookupIndexRecords`, the partition-scoped 
lookup filters file slices by data partition, then unconditionally selects the 
first key and calculates its shard index.
   
   This causes two failures:
   
   - A nonempty lookup for an empty partition throws `ArithmeticException` 
because the matching shard count is zero.
   - An empty-key lookup throws `NoSuchElementException` when accessing the 
first key.
   
   ### Steps to reproduce
   
   1. Create a partitioned table with partitioned RLI enabled.
   2. Write data to partition `p1`, leaving `p2` empty.
   3. Perform either of these point lookups:
   
      ```java
      // Query an empty partition.
      metadata.readRecordIndexLocationsWithKeys(
          HoodieListData.eager(Collections.singletonList("key")),
          Option.of("p2")).collectAsList();
   
      // Query with an empty key collection.
      metadata.readRecordIndexLocationsWithKeys(
          HoodieListData.eager(Collections.emptyList()),
          Option.of("p1")).collectAsList();
      ```
   
   ### Expected behavior
   
   Both lookups return an empty result.
   
   ### Actual behavior
   
   - The lookup for the empty partition throws `ArithmeticException` in 
`mapRecordKeyToFileGroupIndex`.
   - The empty-key lookup throws `NoSuchElementException` in 
`lookupIndexRecords`.
   
   ### Proposed fix
   
   Return an empty result before shard selection when no file slices match the 
requested data partition or the lookup key set is empty.
   
   Preserve the existing metadata index availability checks and continue 
propagating shard read failures.
   


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

Reply via email to