[SPARK-61870][SQL] Fix wrong results when a runtime bloom filter reads a DSv2 scan with a pushed LIMIT again #60672
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 357 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #60672"
general
weight: 0.35
LuciferYang
What changes were proposed in this pull request?
For a key without a DPP filter,
InjectRuntimeFiltertakes a DSv2 scan with a fully pushedLIMIT,OFFSET, top-N orTABLESAMPLEas the creation side of a runtime bloom filter when a selectiveFiltersits 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:
DataSourceV2ScanRelation.isRepeatableRead: whether reading the scan again returns the same rows. It holds for a row-wise scan (onlyRowWisePushdowns), and through a newrepeatableReadflag for a pushed aggregate or join and the target read of a copy-on-write operation.V2ScanRelationPushDownsets the flag unless a limit, offset, top-N or sample is pushed, also into a side of a pushed join, or a pushed aggregate function is not deterministic. The flag defaults to false.isRepeatableRead.Why are the changes needed?
Wrong results. With a source whose reads of a pushed
LIMITreturn other rows, a shuffle join and a fact not partitioned bykwhose scan is abovespark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold, master returns[1]instead of[0]for:The bloom filter comes from another read of
dthan the join's, so it drops the fact rows that match the join's row. ALIMITwithoutORDER 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 a pushed aggregate function that is not deterministic, is no longer a bloom filter's creation side, nor is a scan that a rule outside Spark builds without either flag, as the SQL migration guide now notes. Results are otherwise the same.
How was this patch tested?
New
InjectRuntimeFilterSuitetests: the query above overRotatingLimitDataSourceV2, with AQE on and off; and a scan that reads the same rows again, which stays a creation side under a selectiveFilter, but for a key whose DPP filters are all dropped only if it is row-wise. The SPARK-60702 top-N test now expects no bloom filter onp.f5without DPP either.DataSourceV2TableSampleSuite(a sample on either side of a pushed join),StorageFilterPushDownSuite,JDBCV2SuiteandGroupBasedUpdateTableSuitecheck the flags at the build sites, andDataSourceV2RelationSuiteisRepeatableRead. InJDBCV2Suite, a scan with a pushed aggregate function that is not deterministic also gives no bloom filter in a join.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5.5)