← Back to Pull requests

[FEA] Support Variant values in array and map lookups #16446

Closed
unknown closed this pull request without merging on Nov 03, 2026 03:23 UTC
View on GitHub
unknown unknown commented on Oct 20, 2026 06:58 UTC
Author

Contributes to https://github.com/NVIDIA/cudf-spark/issues/15559.

Stacked on #16445.

Description

This PR enables GetArrayItem and GetMapValue to return Variant values on GPU.

It allows Variant values stored in arrays and map values to reach the existing GPU Variant extraction implementation.

Performance tests (original revisions)

The measurements below use the original revisions recorded in the tables and details. They have not been rerun after this stack update.

On an NVIDIA L4 with Spark 4.1.1 (local[8]), array lookups were 1.60–2.93x faster and map lookups 2.12–2.99x faster; the unchanged struct control had nearly identical median times.

Baseline c9327856c → PR 9cbe8dcaf. Times are median seconds across five measured iterations after two warm-ups. Speedup = baseline / PR; values below 1.0 mean slower. Padding is per Variant value.

| Rows / padding / files | Query | Baseline (s) | PR (s) | Speedup |
| --- | --- | ---: | ---: | ---: |
| 1M / 64 B / 8 | array | 0.500 | 0.312 | 1.60x |
| 1M / 64 B / 8 | map | 0.534 | 0.252 | 2.12x |
| 1M / 64 B / 8 | struct (control) | 0.200 | 0.199 | 1.01x |
| 200k / 4 KiB / 8 | array | 1.013 | 0.346 | 2.93x |
| 200k / 4 KiB / 8 | map | 1.028 | 0.344 | 2.99x |
| 200k / 4 KiB / 8 | struct (control) | 0.163 | 0.163 | 1.00x |

Implementation and validation

GetStructField already accepted Variant results, but the type signatures for GetArrayItem and GetMapValue rejected Variant children.

This change:

  • adds the shim-provided Variant type to the result and child signatures for GetArrayItem and GetMapValue;

  • keeps the change root-safe because older Spark shims contribute an empty Variant signature;

  • updates the generated expression support metadata;

  • adds an end-to-end CPU-write/GPU-read Parquet test for object, array, empty, Variant-null, and SQL-null values in arrays and maps.
  • Test-only regression-review sync at e4d64f9267406a8bce1b9e27f0ba9212a2153d64 (2026-11-02):

    Merged #16445 at 64477b5d94cfda47e85ae78df21121c2510cee7a. Relative to eab09f28e, only the inherited Python read-test coverage changes; production sources are unchanged. The parent review added six field-ID/name-mapping and nested schema-evolution cases across three reader modes. Its focused shared-reader regression runs passed 31 cases on Spark 3.5.9 / Iceberg 1.9.2, 60 on Spark 4.0.4 / Iceberg 1.10.1, and 69 on Spark 4.1.1 / Iceberg 1.11.0: 160 passed, zero failures/errors/skips. This does not replace a separate runtime test of the downstream-specific combination.

    This final head passed all 32 shim profiles against main at 5693fed7121f1747914562c7ec7a26f87aadeaa7, with no static findings. The independent bounded advisory had four combinations without new interactions, one incomplete peer+target conflict (#16595), and 49 unchecked candidates. Earlier revision-specific build/runtime/performance evidence below retains its original scope.

    Correctness follow-up sync at eab09f28ed426cb3ec883503328b48c1757688c6 (2026-11-02):

  • Merged #16445 at 025c4f1c720e50bdf0b61d70861d12752914e648, preserving review history. The six inherited files exactly match #16445's physical-name matching and unannotated-Variant fallback fixes, including the new regressions.

  • The shared-reader changes passed 58 Scala tests and 14 Python cases in each of UTC and Asia/Shanghai at the production revision recorded in #16445. The final parent only adjusts the Python fixture, with identical production sources. This downstream combination was not separately rebuilt or runtime-tested; the downstream-specific evidence below remains tied to its listed revisions.

  • This final head passed all 32 shim profiles against main at 5693fed7121f1747914562c7ec7a26f87aadeaa7, with no static findings. The independent bounded advisory completed four joint static checks without new interaction findings. #16595 was incomplete because its peer+target source tree conflicts; 49 candidates were not checked. These static checks do not establish runtime compatibility.
  • Review-fix stack sync (2026-11-02) at 1fb18ac125838294735efaea549bf9740e721541:

  • Merged #16445 at 9ebfc2fea4bf057728f3dd4c35e29f92c089333b, preserving review history. Relative to d57132727979ccd76a57d69fe041ba50adacf52f, the only changes are 21 inherited Python test lines restoring encrypted-Variant fallback coverage and the three row-lineage fast-suite cases; production sources are unchanged.

  • The restored cases passed on #16445 in both UTC and Asia/Shanghai (4 cases per timezone), and fast-suite collection selected all three row-lineage readers. No new downstream build or runtime run was performed for this test-only merge; the evidence below remains tied to its recorded revisions.

  • This final head passed all 32 shim profiles against main at 5693fed7121f1747914562c7ec7a26f87aadeaa7, with no static findings. The independent bounded advisory found no new static interaction findings with #16687, #16688, #16697, or the pre-fix #16445 head. #16595 could not be checked because its source tree conflicts with main; another 50 candidates were not checked. Static checks do not establish runtime compatibility.
  • Rebase validation (2026-11-02) at d57132727979ccd76a57d69fe041ba50adacf52f:

  • Rebased onto fix/iceberg-variant-read at e8326f18fd23594f80031c67a4b17abcf0a5a7bb, preserving the existing stack dependency and non-UTC test allowances.

  • The final stack at b668190426a96d6e300ee5a36e7b74995104f7be passed a JDK 17 / Scala 2.13 / Spark 4.1.1 clean tests,dist,integration_tests -am install with -DskipTests: test sources compiled and distribution audits passed; Scala unit tests were not executed in this run.

  • On that final stack, test_parquet_nested_array_map_variant_try_get and test_iceberg_v3_nested_variant_read both passed with Iceberg 1.11.0, TZ=UTC, seed 42, and OOM injection disabled: 2 passed, 0 failed, 0 errors, 0 skipped.

  • This PR's combined-tree shim preflight passed all 32 profiles against main at 5693fed7121f1747914562c7ec7a26f87aadeaa7, with no static findings. The independent advisory found no new static interaction findings in four checked peers; one peer combination had conflicting source trees and 49 candidates exceeded the bounded checking scope. These checks do not establish runtime coverage for other Spark versions.
  • Earlier validation at 0c43e621c9930538819869a892046ab531d44069 after merging the updated parent PR, using JDK 17, Spark 4.1.1, Scala 2.13 and Iceberg 1.11.0:

  • Full tests,dist,integration_tests reactor install with test compilation and distribution audits: passed. Versioned generated sources were cleaned before rebuilding.

  • GpuIcebergVariantSchemaSuite: 10 passed; GpuIcebergVariantPostProcessorSuite: 6 passed.

  • Variant read regressions: 5 passed with Maven packages and 5 passed with ICEBERG_EXTRA_CLASSPATH, with zero failures, errors or skips. Coverage includes top-level extraction, direct scalar/null reads, both shredded-reader settings and encrypted-table fallback.

  • Distribution and flat-aggregator JAR revisions match the tested commit; shared unshader placement and obsolete-class removal were checked.

  • test_parquet_nested_array_map_variant_try_get: 1 passed; the captured plan contains GpuGetArrayItem, GpuGetMapValue and GpuVariantGet.
  • Build/package command (JDK 17, with a separate local Maven repository per checkout):

    env -u SPARK_HOME mvn -B -ntp -f scala2.13/pom.xml -Dbuildver=411 \
      -pl tests,dist,integration_tests -am install -DskipTests \
      -Dincluded_buildvers=411 -DparallelForkCount=1
    

    The Scala suites and Python regressions listed above were run separately after packaging.

    <details>
    <summary>Performance test details</summary>

    Revisions and environment

  • Baseline: c9327856c0b25ec86d66f308bcf8727bcab4129d; PR: 9cbe8dcaf667f8a056b90f093926d605baa29c94. Both runs enabled RAPIDS and kept the default CPU bridge enabled.

  • NVIDIA L4 (23,034 MiB), Apache Spark 4.1.1, Scala 2.13, JDK 17.0.17; local[8], 12 GiB driver memory, four concurrent GPU tasks, 2 GiB pinned memory, 128 MiB target GPU batches.

  • Baseline and PR artifacts used the same cuDF/JNI dependencies. Each was built with JDK 17 using mvn -B -f scala2.13/pom.xml install -Dbuildver=411 -Dincluded_buildvers=411 -DskipTests; functional validation was run separately.
  • Data and queries

    CPU-generated, Snappy-compressed Parquet, read through the V1 source. Data was generated once on CPU and reused unchanged. The datasets have 1,000,000 rows with 64-byte padding, or 200,000 rows with 4,096-byte padding. Each dataset has eight files.

    The logical schema is:

    id:         BIGINT
    payload:    STRUCT<v: VARIANT>
    items:      ARRAY<VARIANT>
    attributes: MAP<STRING, VARIANT>
    

    Each Variant contains an object or array with an integer and padding derived from a row-specific SHA-256 hex string, repeated to the requested length. Padding size is not the entire serialized Variant size; the repeated padding is compressible. Each case includes 1% SQL-null Variant values, 1% JSON-null Variant values, and 1% empty Variant objects/arrays.

    The three workloads project these expressions, then aggregate row count, non-null count, and sums to consume the extracted integers:

    -- array
    try_variant_get(items[0], '$.x', 'int')
    try_variant_get(items[1], '$[0]', 'int')
    -- map
    try_variant_get(attributes['object'], '$.x', 'int')
    try_variant_get(attributes['array'], '$[0]', 'int')
    -- struct
    try_variant_get(payload.v, '$.x', 'int')
    

    items[1] indexes the outer SQL array (GetArrayItem / GpuGetArrayItem); attributes['array'] indexes the SQL map (GetMapValue / GpuGetMapValue). The JSON paths inside try_variant_get are evaluated by GpuVariantGet when GPU execution is selected.

    Configuration and measurement

    spark.sql.adaptive.enabled=false
    spark.sql.shuffle.partitions=8
    spark.rapids.sql.format.parquet.reader.type=MULTITHREADED
    spark.rapids.sql.incompatibleOps.enabled=true
    spark.sql.variant.pushVariantIntoScan=false
    spark.sql.variant.allowReadingShredded=false
    spark.sql.variant.writeShredding.enabled=false
    spark.rapids.filecache.enabled=false
    spark.sql.sources.useV1SourceList=parquet
    

    Each revision ran two warm-ups followed by five measured iterations per case, baseline first and PR second. A fresh DataFrame/query was constructed for every action to prevent reuse of a previous shuffle result. Timings include planning, scan, extraction, aggregation, and collection, and exclude data generation and JVM startup. Every warm-up and measured result was checked against deterministic expected counts and sums; captured physical plans were also checked.

    No Spark persistence or RAPIDS file cache was used; the OS page cache was warm. These are local, synthetic, unshredded-Variant microbenchmarks, so the results do not establish performance for remote storage, cold caches, shredded data, or arbitrary production workloads.

    Observed execution

    Both revisions used a GPU Parquet scan and GpuVariantGet. The baseline performed collection access through GpuCpuBridgeExpression wrapping GetArrayItem / GetMapValue; the PR used GpuGetArrayItem / GpuGetMapValue directly. The struct query follows an unchanged path and serves as a control.

    </details>

    AI assistance disclosure: Codex assisted with implementation and validation.

    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: 19944m
    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 #16446"
    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%