← Back to Pull requests

Enable key-only range sampling for seeded random clustering keys [databricks] #16252

Closed
unknown closed this pull request without merging on Oct 27, 2026 20:59 UTC
View on GitHub
unknown unknown commented on Oct 09, 2026 18:47 UTC
Author

Fixes #15445 and fixes #16613 .

Description

Enable key only range boundary sampling for the seeded random tie breaker generated by Delta liquid clustering. The existing pruning guard requires all selected projection expressions to be deterministic. As a result, liquid clustering plans containing GpuRand fall back to reading the full table schema during boundary collection, even when spark.rapids.sql.rangePartitioning.sampleKeysOnly=true.

This change allows GpuRand with an integer or long literal seed and GPU expression wrappers whose own evaluation is deterministic. It also tracks filter dependencies through projection aliases and requires those dependencies to remain deterministic. Direct or aliased random filters, unsupported nondeterministic expressions, and unsupported plan nodes retain the existing fallback path.

Boundary samples supply advisory split points. The original exchange child and ordering comparator remain unchanged, so output rows and their values still come from the original input plan. Re-evaluating a random sampling key can change approximate partition balance but it does not replace output row values.

Validation

  • Added coverage in GpuRangeBoundaryPlanSuite for seeded random keys, expression wrappers, alias dependencies, and unsafe-expression/filter fallbacks.

  • Added coverage in NonDeterministicRetrySuite for seeded random streams across batch sizes, empty batches, partitions, and checkpoint restoration.

  • All 34 tests passed across GpuRangeBoundaryPlanSuite, NonDeterministicRetrySuite, and ProjectSplitRetrySuite, including retry and split-retry coverage.
  • Performance

    Reproduced the issue's write workflow: create an empty Delta table clustered by session_id, clear caches, and append the source. Automatic optimization performs liquid clustering during the append; no separate explicit OPTIMIZE is issued. All runs used the same cloned source pinned to version 0: 5,887,163 rows and 585 columns.

    The driver was an r7i.2xlarge. Each run used two executors with four Spark cores, 60 GiB heap, and 52 GiB memory overhead. GPU runs used g4dn.8xlarge executors, 2 GiB input partitions, 512 MiB GPU batches, and GPU concurrency 1. The CPU run used the issue's i7i.4xlarge executors and 128 MiB input partitions.

    Table properties followed the issue's respective CPU/GPU configurations. Both enabled automatic optimized writes, automatic compaction, checkpoint v2, and statistics on session_id. CPU additionally enabled deletion vectors, row tracking, change data feed, and name-based column mapping. GPU disabled deletion vectors and left the other three features unset.

    | Variant | Append including automatic clustering | Initial write | Clustering | GPU boundary collection |
    | --- | ---: | ---: | ---: | ---: |
    | CPU, original issue settings | 1,349.208 s | 500.064 s | 826.618 s | — |
    | GPU, both optimizations disabled | 1,660.069 s | 679.455 s | 970.823 s | 298.207 s |
    | GPU, both optimizations enabled | 1,465.430 s | 681.226 s | 773.686 s | 262.007 s |
    | GPU, this candidate, both optimizations enabled | 1,213.269 s | 677.774 s | 525.062 s | 2.597 s |

    “Both optimizations” refers to spark.rapids.sql.rangePartitioning.sampleKeysOnly and spark.rapids.sql.rangeShuffle.inputBatching.enabled from #15925 and #15941.

    Compared with the merged implementation with both optimizations enabled, this candidate reduced boundary collection time by approximately 101×, clustering elapsed time by 32.1%, and total append elapsed time by 17.2%. Total append elapsed time was 26.9% lower than GPU with both optimizations disabled and 10.1% lower than CPU with the original issue's CPU settings. Initial GPU writes remained slower than CPU writes.

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • (Please provide the names of the existing tests in the PR description.)
  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 533 lines (+399 / -134) across 6 files Reviewer: sdrp713 Review duration: 26051m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 533 lines diff across 6 files
    0.48
    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.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16252"
    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: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    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: 18.9% · Safe to merge
    18.9%