← Back to Pull requests

Accelerate Spark unhex with GPU decoding [databricks] #16348

Closed
unknown closed this pull request without merging on Oct 27, 2026 22:17 UTC
View on GitHub
unknown unknown commented on Oct 14, 2026 20:38 UTC
Author

Fixes #12579.

Depends on NVIDIA/cudf-spark-jni#5294, which is merged. CI needs the next cudf-spark-jni 26.12.0-SNAPSHOT that includes it.

Description

  • GPU unhex: add GpuUnhex, which calls the new JNI CastStrings.hexToBytes. Odd-length input is decoded as if it had a leading zero, and invalid input returns null.

  • Rule and fallback: register Unhex (string to binary) with UnhexRuleMeta. Strict-mode detection uses version-specific typed UnhexShims accessors instead of constructor-position inspection. Error-raising to_binary(..., 'hex') on Spark 3.4+ falls back to the CPU; permissive to_binary(..., 'hex') on Spark 3.3 runs on the GPU.

  • Config: spark.rapids.sql.expression.Unhex, enabled by default, added in 26.12.0.

  • Docs: new "Hexadecimal to Binary" section in docs/compatibility.md, including the odd-length CPU decoding difference on Spark 3.3.0/3.3.1 (SPARK-40924) and Databricks runtimes, and the internal Databricks behavior switch. The GPU returns the corrected result on every supported version. Regenerated supported_ops.md, advanced_configs.md, and tool CSVs.

  • Tests: CPU/GPU comparisons for unhex (fixed, generated, hex(unhex(a))) and permissive to_binary on Spark 3.3; fallback and error-parity checks for error-raising to_binary; test_unhex_odd_length checks GPU bytes and hex(unhex(a)) directly. Databricks tests cover both values of spark.databricks.behaviorChange.SC114071UnhexConvertOddSymbol.enabled. CPU/GPU comparisons retain null inputs and exclude odd-length rows only where the CPU retains legacy decoding; they compare odd-length inputs when the Databricks correction is enabled.
  • Typed-shim follow-up validation: commit b0ca203d8d784c259a6b544dd67c85b3719f47cd replaces positional strict-mode detection with typed accessors. The selected accessor compiled and passed default/strict-mode probes against all 39 supported OSS Spark/Scala profile combinations. This is targeted accessor validation, not a full distribution build for every OSS profile.

    Incremental package builds and the targeted GPU selection passed on DBR 14.3, 17.3, and 18.3 at the follow-up source revision: 14 passed and 2 expected skips on each runtime. DBR 17.3 additionally passed a direct false/true accessor probe. The configured repository style check passed with zero errors or warnings.

    A distribution containing both Spark 3.3 and DBR 14.3 shims also built successfully. The same jar passed the OSS Spark 3.3 GPU tests (7 passed, 2 expected skips), including permissive to_binary, and the DBR 14.3 tests (14 passed, 2 expected skips), including strict CPU fallback/error parity. The jar contains separate implementations in the expected version directories. These checks exercise both accessor variants and their runtime selection. The decoder implementation is unchanged by this follow-up.

    Review follow-up (d4ca18656f): added the missing Spark master (500) shim provider, documented strict/try_to_binary CPU fallback and legacy odd-length differences in the generated support notes, and added long-row, all-null, empty-batch, and try_to_binary fallback tests. Clean bounded multi-shim distribution builds passed for Scala 2.12 (334,340) and Scala 2.13 (400,420); Python syntax and shimpler source-graph tests passed. The Spark master build selects the new provider but its full compilation is blocked by an unchanged GpuJsonScan JSON parser API incompatibility. The new GPU integration tests have not been rerun locally.

    Databricks validation: clean Maven package builds and targeted GPU integration tests passed on commit 145d2da4f79703a451f6b10eada10aa351c44a5d, which includes a merge of main at 049e74954e3d1492a18910d2d78c6fddee303a63.

    | Databricks Runtime | Spark | Scala | Clean package | unhex or to_binary_hex |
    | --- | --- | --- | --- | --- |
    | 14.3 | 3.5.0 | 2.12 | Passed | 14 passed, 2 skipped |
    | 17.3 | 4.0.0 | 2.13 | Passed | 14 passed, 2 skipped |
    | 18.3 | 4.1.0 | 2.13 | Passed | 14 passed, 2 skipped |

    The two skips on each runtime are the Spark-3.3-only permissive to_binary cases. Maven test execution was skipped for packaging; the targeted Python GPU tests ran separately. Builds used the system-scope runtime dependency generator against /databricks/jars, without first installing those runtime jars into Maven.

    Separate CPU probes confirmed that the internal Databricks switch defaults to false on all three runtimes. With it disabled, hex(unhex('ABC')) returns BC00; with it enabled, it returns 0ABC. The GPU tests passed with both settings.

    For performance, Spark 4.1.1 ran locally with four CPU task slots against the same single-partition Parquet input. Each run used five warmups and ten timed fresh queries of SUM(CASE WHEN UNHEX(a) IS NOT NULL THEN 1 ELSE 0 END). The CPU run used vanilla upstream Spark without RAPIDS; the GPU run used this plugin with the matching JNI implementation. Medians include scan, decode, aggregate, and collect(), rather than isolated expression time.

    | 1 GiB logical hex-string input | Vanilla CPU Spark | GPU Spark |
    | --- | ---: | ---: |
    | 67,108,864 unique 16-character strings | 1,608.7 ms | 324.3 ms |
    | Same input with one 1 MiB string | 1,708.2 ms | 345.7 ms |

    These results show approximately 5× faster end-to-end execution at this scale; they do not imply a speedup for smaller batches. Host: AMD Ryzen Threadripper PRO 5975WX and NVIDIA Quadro RTX 6000.

    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

  • (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: 650 lines (+487 / -163) across 8 files Reviewer: sdrp713 Review duration: 18818m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16348"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%