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

   ### What changes were proposed in this pull request?
   
   For a key without a DPP filter, `InjectRuntimeFilter` takes a DSv2 scan with 
a fully pushed `LIMIT`, `OFFSET`, top-N or `TABLESAMPLE` as the creation side 
of a runtime bloom filter when a selective `Filter` sits above it. The bloom 
filter's subquery reads the scan again, apart from the join, and such a scan 
may return other rows on that read.
   
   This PR:
   
   - Adds `repeatableRead` to `DataSourceV2ScanRelation`: whether reading the 
scan again returns the same rows. `V2ScanRelationPushDown` sets it unless a 
limit, offset, top-N or sample is pushed, also into a side of a pushed join. 
Unlike `onlyRowWisePushdowns`, it holds for a pushed aggregate or join and for 
the target read of a copy-on-write operation. `onlyRowWisePushdowns` requires 
it. It defaults to false.
   - Takes a DSv2 scan as a bloom filter's creation side only if it is 
`repeatableRead`.
   
   ### Why are the changes needed?
   
   Wrong results. With a source whose reads of a pushed `LIMIT` return other 
rows, a shuffle join, a fact scan above 
`spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold` and 
DPP off, master returns `[1]` instead of `[0]` for:
   
   ```sql
   SELECT count_if(f.id IS NULL)
   FROM (SELECT * FROM dim LIMIT 1) d LEFT JOIN fact f ON d.i = f.k
   WHERE d.i > 0
   ```
   
   The bloom filter comes from another read of `d` than the join's, so it drops 
the fact rows that match the join's row. A `LIMIT` without `ORDER BY`, or a 
top-N with ties, can behave this way.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, it fixes the wrong results above. A DSv2 scan with a pushed limit, 
offset, top-N or sample, or one built by a rule that does not set 
`repeatableRead`, is no longer a bloom filter's creation side. Results are 
otherwise the same.
   
   ### How was this patch tested?
   
   New `InjectRuntimeFilterSuite` tests: the query above over 
`RotatingLimitDataSourceV2`, with AQE on and off; and a scan that reads the 
same rows again but is not row-wise, which stays a creation side under a 
selective `Filter`, but not for a key whose DPP filter is dropped. The 
SPARK-60702 top-N test now expects no bloom filter on `p.f5` without DPP 
either. `DataSourceV2TableSampleSuite`, `StorageFilterPushDownSuite`, 
`JDBCV2Suite` and `GroupBasedUpdateTableSuite` check `repeatableRead` at the 
build sites, and `DataSourceV2RelationSuite` that `onlyRowWisePushdowns` 
requires it.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 5.5)
   


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