Accelerate Spark unhex with GPU decoding [databricks] #16348
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
sdrp713
Fixes #12579.
Depends on NVIDIA/cudf-spark-jni#5294, which is merged. CI needs the next
cudf-spark-jni26.12.0-SNAPSHOT that includes it.Description
unhex: addGpuUnhex, which calls the new JNICastStrings.hexToBytes. Odd-length input is decoded as if it had a leading zero, and invalid input returns null.Unhex(string to binary) withUnhexRuleMeta. Strict-mode detection uses version-specific typedUnhexShimsaccessors instead of constructor-position inspection. Error-raisingto_binary(..., 'hex')on Spark 3.4+ falls back to the CPU; permissiveto_binary(..., 'hex')on Spark 3.3 runs on the GPU.spark.rapids.sql.expression.Unhex, enabled by default, added in 26.12.0.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. Regeneratedsupported_ops.md,advanced_configs.md, and tool CSVs.unhex(fixed, generated,hex(unhex(a))) and permissiveto_binaryon Spark 3.3; fallback and error-parity checks for error-raisingto_binary;test_unhex_odd_lengthchecks GPU bytes andhex(unhex(a))directly. Databricks tests cover both values ofspark.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
b0ca203d8d784c259a6b544dd67c85b3719f47cdreplaces 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_binaryCPU fallback and legacy odd-length differences in the generated support notes, and added long-row, all-null, empty-batch, andtry_to_binaryfallback 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 unchangedGpuJsonScanJSON 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 ofmainat049e74954e3d1492a18910d2d78c6fddee303a63.| 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_binarycases. 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
falseon all three runtimes. With it disabled,hex(unhex('ABC'))returnsBC00; with it enabled, it returns0ABC. 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, andcollect(), 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
Testing
(Please provide the names of the existing tests in the PR description.)
Performance