← Back to Pull requests

[SPARK-61870][SQL] Fix wrong results when a runtime bloom filter reads a DSv2 scan with a pushed LIMIT again #60672

Closed
unknown closed this pull request without merging on Nov 22, 2026 16:36 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 13:43 UTC
Author

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 DataSourceV2ScanRelation.isRepeatableRead: whether reading the scan again returns the same rows. It holds for a row-wise scan (onlyRowWisePushdowns), and through a new repeatableRead flag for a pushed aggregate or join and the target read of a copy-on-write operation. V2ScanRelationPushDown sets 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.

  • Takes a DSv2 scan as a bloom filter's creation side only if it isRepeatableRead.
  • Why are the changes needed?

    Wrong results. With a source whose reads of a pushed LIMIT return other rows, a shuffle join and a fact not partitioned by k whose scan is above spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold, master returns [1] instead of [0] for:

    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 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 InjectRuntimeFilterSuite tests: the query above over RotatingLimitDataSourceV2, with AQE on and off; and a scan that reads the same rows again, which stays a creation side under a selective Filter, 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 on p.f5 without DPP either. DataSourceV2TableSampleSuite (a sample on either side of a pushed join), StorageFilterPushDownSuite, JDBCV2Suite and GroupBasedUpdateTableSuite check the flags at the build sites, and DataSourceV2RelationSuite isRepeatableRead. In JDBCV2Suite, 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)

    Diff: 357 lines (+267 / -90) across 4 files Reviewer: LuciferYang Review duration: 5933m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%
    Repository