← Back to Pull requests

Preserve accumulator cast semantics in array aggregate [databricks] #17012

Closed
unknown closed this pull request without merging on Nov 24, 2026 14:13 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 08:14 UTC
Author

Fixes #16918.

Description

Dropping a narrowing accumulator cast in an array aggregate could return the wrong value or suppress an ANSI overflow. For non-ANSI integer sums of the form cast(acc as narrower_integer) + x or its reverse, where x has the accumulator type, the GPU now narrows the prefix sum and adds the last element at the original width. For a zero initial value and a cast through TINYINT, this gives 128 for [127, 1] and -128 for [127, 1, 0]. Other value-changing casts (including those in greatest, try_cast, and ANSI sums) as well as TRY or ANSI-retained SUM/PRODUCT merge operations fall back to Spark. Exact casts still run on GPU.

This also moves the user-facing ArrayAggregate support and CPU-fallback explanation out of docs/compatibility.md into GpuCollectionExpressionOverrides (regenerating docs/supported_ops.md and docs/additional-functionality/advanced_configs.md). Unsupported lambda shapes fall back to CPU with Spark-compatible results rather than introducing compatibility differences: the only GPU/CPU divergence (variableFloatAgg on floating-point SUM/PRODUCT) remains documented under Floating Point in docs/compatibility.md, supported shapes and fallback reasons live in docs/supported_ops.md and docs/additional-functionality/advanced_configs.md, and spark.rapids.sql.explain reports the exact fallback reason per query.

Validation:

  • Ran ArrayAggregateDecomposerSuite and GpuArrayHofFusionSuite on Spark 3.5.2 (58 Scala tests passed), higher_order_functions_test.py (80 integration tests passed, including wide-sum wraparound cancellation and try_cast/try_add/try_multiply fallbacks), and tools docgen on Spark 3.3.0.

  • Reported by the author: across six narrowing type pairs on Spark 3.5.2, both operand orders matched Spark CPU on 12,336 inputs (including empty arrays, nulls, and overflow); after merging #16687, the full Spark 3.5.2 distribution build passed, including standalone extraction of the zstd-chunked libcudf.so with zstd-jni on the classpath.
  • Median end-to-end times reported on an RTX 5880 Ada over 10 warm runs per case (measured on aa4d2f9d prior to merging main and follow-up test/guard updates). Each run checked all 524,288 results for arrays of 32 in-range integers.

    | Accumulator cast | Original GPU | Published draft | Updated GPU |
    | --- | ---: | ---: | ---: |
    | INT → TINYINT → INT | 235.5 ms | 886 ms (CPU fallback) | 270.5 ms |
    | INT → BIGINT → INT | 235 ms | 234.5 ms (GPU) | 232 ms |

    AI assistance was used to implement and validate this change.

    Checklists

    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

  • 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: 374 lines (+280 / -94) across 4 files Reviewer: wjxiz1992 Review duration: 8999m
    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 · 374 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.355
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #17012"
    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.9% (MEDIUM) · Higher = larger blast radius
    42.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: 16.9% · Safe to merge
    16.9%