← Back to Pull requests

from_protobuf: Return fields the query does not read as nulls on the GPU [databricks] #16697

Closed
unknown closed this pull request without merging on Nov 25, 2026 14:07 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 04:54 UTC
Author

Part of #14069. Uses the hidden-field null-column support merged in NVIDIA/cudf-spark-jni#5372.

Description

The GPU from_protobuf decodes and returns every field of the message, even when the query reads only a few of them. Spark still parses the whole message, so fields the query does not read must keep being validated, but they do not need to be materialized.

The planner now traces which fields of the decoded struct the query reads, through struct field and array element accesses in projections, filters, sorts and aggregates. It passes unread fields to the decoder as hidden (isOutput = false). With NVIDIA/cudf-spark-jni#5372, the decoder still validates hidden fields like Spark does, including those inside nested and repeated messages, but returns them as nulls. So the expression keeps Spark's output type, and no operator above it changes.

To preserve Spark semantics across all plans and boundaries:

  • Any other use of the struct, the struct reaching another kind of plan or the query output, or failing to locate the decode expression in its own plan reads the struct as a whole.

  • The decode expression is matched by reference identity as well as semanticEquals, so semantically equal copies take the union (keeping GpuTieredProject CSE intact so semantically equal copies in the same projection decode once) while non-deterministic inputs still trace their own reads instead of hiding every field.

  • Non-nullable fields (proto2 required) remain visible under visible parents so Spark's UnsafeProjection (in GpuCpuBridgeExpression and GpuColumnarToRowExec) never dereferences nulls in nullable = false struct slots. Unread nullable messages (optional and repeated) still hide their entire subtrees, including nested required fields.
  • This replaces the schema projection in the draft #14354, which changed the output type of the expression, with a smaller change.

    User-facing: none. Results are unchanged; queries that read some of the fields use less GPU memory.

    Tests:

  • ProtobufSchemaSuite covers merging field reads, JNI schema validation for hidden children of an output message, and FieldReads.analyzePlans across carried ProjectExec (alias and pass-through), FilterExec, SortExec, HashAggregateExec (grouping, aggregate argument, aggregate filter, and whole-struct grouping), ElementAt with dynamic index reads, GetArrayItem, unsupported/root boundaries, dropped structs, unmatched fail-closed fallback, and non-deterministic decodes.

  • protobuf_test.py checks, for each decode in the GPU plan, which fields it outputs: top-level fields, nested leaves, array elements via get, try_element_at, and array-of-struct extraction, reads through a non-collapsed alias projection, pushed-down and carried filters, sort and aggregate queries, whole-struct/whole-child reads, and non-deterministic inputs.

  • protobuf_test.py also verifies that non-nullable required fields stay output under visible parents (while optional children and required fields under hidden optional messages stay hidden) and execute cleanly across GpuCpuBridgeExpression and CPU FilterExec fallback paths.

  • A new malformed-input case reads a field of a nested message whose unread repeated message sibling misses a required field. Existing malformed cases that select only some fields also exercise validation of hidden fields.
  • Locally validated on Spark 3.5.2 (-Dbuildver=352) against the published nightly cudf-spark-jni 26.12.0-SNAPSHOT (revision bd15415531c40a2e83067d91147fcfa51a317b1d):

  • ProtobufSchemaSuite, ProtobufExprShimsSuite, and SparkProtobufCompatSuite: 50 tests passed.

  • TEST_PARALLEL=1 INCLUDE_SPARK_PROTOBUF_JAR=true ./integration_tests/run_pyspark_from_build.sh -k protobuf: 120 tests passed.

  • Verified GpuCpuBridgeExpression and CPU FilterExec fallback cases on hidden required schemas with JVM assertions enabled (-ea).

  • mvn -N -Dbuildver=352 -Dspark.rapids.source.basedir=$PWD antrun:run@scalastyle-all-modules: 0 errors, 0 warnings.

  • build/check_shim_compatibility.py coverage: PASS (35 profiles, 4465 checks, 0 findings); GitHub Actions shim-compatibility and shim-related-prs passed on head d42def938.
  • Not run locally: other Spark versions (including Scala 2.13) and Databricks runtimes.

    Performance: Measured per-task GPU memory peak (gpuMaxTaskFootprint) with a local benchmark on one RTX 5880 Ada, Spark 3.5.2 local[8] (measured on commit 25d9ef6f prior to merging main, the final merged NVIDIA/cudf-spark-jni#5372 snapshot, and keeping non-nullable fields visible under visible parents). The serialized messages come from Spark's CPU cache, so they reach the GPU without a GPU Parquet scan, as from Kafka. Results equal those of the current plugin.

    | Message | Fields read | Before | After |
    |---|---|---|---|
    | 50K x 34 KB, nested and repeated messages | 3 of 20 top-level scalars | 340 MiB | 171 MiB |
    | | one leaf 3 levels deep | 340 MiB | 171 MiB |
    | | one field of a repeated message | 340 MiB | 173 MiB |
    | 500K x 1.7 KB, repeated messages | one field of a repeated message | 315 MiB | 184 MiB |
    | 1M x 174 B, 3-level nested messages | 2 leaves | 113 MiB | 81 MiB |

    When the messages are read from Parquet on the GPU, the scan peak is higher than the decode peak, so the task peak does not change.

    Under GPU memory pressure the smaller footprint also saves time. With 8 concurrent GPU tasks and the RMM pool limited to 1 GiB or 768 MiB (spark.rapids.memory.gpu.allocSize), reading 3 top-level scalars or one field of a repeated message from the 34 KB messages spilled 360-500 MiB and retried allocations 3-5 times per query before this change, taking 0.94-1.32 s (median of 3). After it, those queries did not spill or retry and took 0.69-0.71 s. Reading every field spilled and took the same time with and without the change. With a 1.5 GiB or larger pool, and in the default configuration, query time did not change measurably, from Parquet or from the CPU cache.

    This change was developed with AI assistance.

    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: wjxiz1992 Review duration: 33672m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). 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%
    56%
    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 #16697"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 22.5% · Safe to merge
    22.5%