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

   ### Bug Description
   
   A cached view of a merge-on-read table (`CACHE TABLE` over a query of the 
table, or a cached DataFrame) keeps returning rows that a later `DELETE`, 
`UPDATE` or `MERGE INTO` changed. Copy-on-write tables are not affected.
   
   **What happened:**
   
   `HoodieBaseHadoopFsRelationFactory` resolves `queryTimestamp` once when the 
relation is built (the latest completed instant at that point) and passes it to 
`HoodieFileGroupReaderBasedFileFormat`, which uses it as the file group 
reader's latest commit time. After a DML statement, `refreshTable` refreshes 
the file index and Spark re-executes the cached plan. The file index reloads 
the timeline and lists the new log files, but the reader still stops at the old 
instant and skips their blocks, so the view misses the change. On a 
copy-on-write table the new base files come from the file index alone, so the 
view is correct.
   
   **What you expected:**
   
   Without a time travel instant, a re-executed scan should read up to the 
latest completed instant of the timeline its file index lists against.
   
   **Steps to reproduce:**
   
   ```sql
   create table t (id int, name string, price double, ts long) using hudi
     tblproperties (type = 'mor', primaryKey = 'id', preCombineField = 'ts');
   insert into t values (1, 'a1', 10.0, 1000), (2, 'a2', 10.0, 1000);
   create temporary view v as select id, name from t where id = 1;
   cache table v;
   select * from v;            -- (1, a1)
   delete from t where id = 1; -- writes a log file
   select * from v;            -- still (1, a1), expected no rows
   ```
   
   **Proposed fix:** only a time travel query pins the instant; otherwise the 
file format resolves the latest completed instant from the relation's meta 
client (the one its file index reloads) when it builds the reader.
   
   **Related:** `validCommits` in the same factory is also computed once from 
the timeline at build time. It is only set for schema-on-read tables and is 
used to resolve the schema version of base files, so after a refresh a base 
file written by a newer commit is looked up against a stale commit list. I have 
not seen a wrong result from it (the schema lookup falls back to the latest 
schema at or below the file's version), so I am leaving it out of the fix above.
   
   ### Environment
   
   **Hudi version:** master (1.3.0-SNAPSHOT)
   **Query engine:** Spark 3.5
   **Relevant configs:** merge-on-read table, default reader configs
   
   ### Logs and Stack Trace
   
   No exception; the cached view returns the stale row.
   


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