← Back to Pull requests

[SPARK-60808][SQL] Fix lost join rows when a runtime bloom filter's creation side is non-deterministic #60176

Closed
unknown closed this pull request without merging on Nov 06, 2026 19:43 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 13:01 UTC
Author

What changes were proposed in this pull request?

InjectRuntimeFilter no longer builds a runtime bloom filter from a creation side whose filter or key is non-deterministic.

The check runs on the bloom filter's subquery after column pruning, next to the existing Python UDF check. So a non-deterministic column that the bloom filter does not read still allows the bloom filter.

Known limit: the check sees only the non-determinism that the plan shows. A leaf can hide it when reading the leaf again returns other rows, for example:

  • a cache whose plan is not repeatable, if part of the cache is computed again;

  • a V2 scan with a pushed limit, top-N or sample;

  • a LogicalRDD that is not a materialized checkpoint, such as the DataFrame of a foreachBatch micro-batch.
  • DPP has the same gap, see the comment on PartitionPruning.isCheaplyRecomputableMaterializedPlan. Closing it needs a repeatability check for each leaf type. Master has one only for some leaves, and the 4.0 to 4.2 branches have none. #58635 adds such a check for its RUNTIME_FILTER hint, so the default path can use it on master in a follow-up.

    Why are the changes needed?

    The bloom filter's subquery evaluates the creation side a second time, apart from the join. With a non-deterministic filter or key, the two evaluations can keep different rows or give different keys. The bloom filter can then drop application side rows that match a creation side row the join sees, and the query loses rows.

    Example from the ticket, where every dim.k is in fact, so lost must be 0:

    CREATE TABLE dim USING parquet AS SELECT cast(id AS INT) k FROM range(200);
    CREATE TABLE fact USING parquet AS SELECT cast(id % 200 AS INT) k, id v FROM range(20000);
    SET spark.sql.autoBroadcastJoinThreshold=-1;
    SET spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold=1;
    SELECT count(*) total, count_if(f.k IS NULL) lost
    FROM (SELECT k FROM dim WHERE cast(reflect('java.lang.Math', 'random') AS DOUBLE) < 0.5) d
    LEFT JOIN fact f ON d.k = f.k;
    

    Before this change, three runs gave lost = 47, 46 and 47. After it, lost is 0.

    Does this PR introduce _any_ user-facing change?

    Yes. A join whose bloom filter creation side has a non-deterministic filter or key no longer loses rows. Such a join no longer gets a bloom filter built from that side. That includes a sampling filter like rand() < 0.1, even though its two scans usually keep the same rows.

    How was this patch tested?

    New tests in InjectRuntimeFilterSuite:

  • the bloom filters of three creation sides:

  • - a non-deterministic filter: no bloom filter;
    - a non-deterministic key: no bloom filter;
    - a non-deterministic column that the bloom filter does not read: the bloom filter stays;
  • the example above, with checkAnswer on lost, and a deterministic creation side on the same tables that gets a bloom filter.
  • Before this change, the first two creation sides got a bloom filter, and the example lost rows. Checking the creation side plan instead of the pruned subquery fails the third creation side.

    InjectRuntimeFilterSuite, BloomFilterAggregateQuerySuite, the DPP suites, the runtime filter suites, StorageFilterPushDownSuite and the plan stability suites pass, with no plan change.

    Was this patch authored or co-authored using generative AI tooling?

    Generated-by: Claude Code with Claude Opus 5.5

    Diff: 424 lines (+318 / -106) across 5 files Reviewer: peter-toth Review duration: 402m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 424 lines diff across 5 files
    0.45
    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.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #60176"
    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: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    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: 17.8% · Safe to merge
    17.8%
    Repository