vinishjail97 opened a new pull request, #20785:
URL: https://github.com/apache/hudi/pull/20785

   ### Describe the issue this Pull Request addresses
   
   `HoodieFileIndex` is a case class whose generated `equals`/`hashCode` 
include `fileStatusCache`. The relation path passes 
`FileStatusCache.getOrCreate(spark)`, which returns a new client object on 
every call, and that object only has identity equality. As a result, two 
`HoodieFileIndex` instances over the same table and the same snapshot never 
compare equal.
   
   Spark relies on relation equality for plan-level dedup. 
`MergeScalarSubqueries` cannot merge scalar subqueries that scan the same Hudi 
table, so queries such as TPC-DS q9 and q28 scan the fact table once per 
subquery instead of once in total.
   
   ### Summary and Changelog
   
   - `HoodieFileIndex` overrides `equals`/`hashCode` and leaves out 
`fileStatusCache`.
   - Leaving out the cache alone would make an index built after a commit equal 
to a cached index of the earlier snapshot, so `CacheManager` would return stale 
rows. Equality therefore also includes the snapshot the index was built on: the 
latest completed instant at construction, as (requested time, completion time).
   - Tests:
     - `testEqualityIgnoresFileStatusCache`: two indexes with separate 
`FileStatusCache` clients are equal and have the same hash code; different 
options are not equal.
     - `testCachedReadNotReusedAfterCommit`: a cached read is reused for the 
same snapshot, and is not reused after a new commit (the new read returns 150 
rows, not the cached 100).
   
   ### Impact
   
   Scalar subqueries over the same Hudi table can be merged into one scan. 
Cached reads are never reused across a commit. No public API or config change.
   
   ### Risk Level
   
   low. The change only affects `HoodieFileIndex` equality, which plan dedup 
and `CacheManager` lookups use. Both directions are covered by the new tests.
   
   ### Documentation Update
   
   none
   
   ### Contributor's checklist
   
   - [x] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [x] Enough context is provided in the sections above
   - [x] Adequate tests were added if applicable
   


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

  • [PR] fix(spark): make HoodieFil... vinishjail97 (via GitHub) via commits

Reply via email to