← Back to Pull requests

Support Iceberg v3 write defaults in GPU writes [reduced-it] #17100

Closed
unknown closed this pull request without merging on Nov 27, 2026 03:00 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 09:17 UTC
Author

closes #15437

Description

Use Iceberg v3 write defaults when deciding whether a data write can run on the GPU. Scans check initial defaults. A position-only DELETE checks the delete schema, so an unrelated table-column default does not force CPU fallback.

Spark and the Iceberg catalog resolve an omitted column before writing. For example, on Spark 4.1.1 with Iceberg 1.11.0, both writers materialize 'current' when the INSERT omits the column and preserve an explicit NULL. When Spark rejects the omitted-column INSERT, the GPU matches the CPU error. The GPU writer copies defaults present in the actual write schema into the Parquet footer. A default stripped from that schema stays absent even when the table schema still declares it. Existing cuDF interfaces write the resolved columns and footer metadata. This change requires no native cuDF or JNI changes.

<details>
<summary>Three parity checks and 13 scenarios</summary>

Compare independent CPU and GPU tables at three levels: SQL rows or errors, raw Parquet column values, and persisted default presence and value by field ID. The CPU footer uses iceberg.schema and the GPU footer uses Spark schema JSON. Read the files through Iceberg FileIO and PyArrow so an Iceberg reader cannot supply a missing physical value during the comparison.

| # | Scenario | Expected result |
|---|---|---|
| 1 | Read a row written before adding the column | The reader returns the initial default 'legacy'; the column is absent on disk and the file hash stays unchanged. |
| 2 | INSERT omits the column | Match the CPU default or CANNOT_FIND_DATA; a rejected write leaves existing files intact. |
| 3 | INSERT supplies an explicit string | Persist the supplied value. |
| 4 | INSERT supplies NULL | Persist NULL. |
| 5 | Change the write default between inserts | Where omission succeeds, persist 'current' then 'next' in their respective generations. |
| 6 | Update the table default without DML | Preserve the initial default and all existing file hashes. |
| 7 | Matched MERGE updates a different column | Retain 'legacy' on the matched row. |
| 8 | Unmatched MERGE omits the column | Match the CPU insert value, including on the insert-only append path. |
| 9 | Matched MERGE explicitly sets the column to NULL | Persist NULL on the updated row. |
| 10 | The actual writer schema carries or omits defaults | Preserve field IDs, distinct supplied defaults and absent defaults. Unit tests also distinguish both instants in a daylight-saving overlap. |
| 11 | Append or MERGE encounters a write-only fixed[2] default | Check CPU fallback separately for append, copy-on-write and merge-on-read. |
| 12 | Partial position DELETE on the same schema | Execute the GPU delta write and check the surviving row. |
| 13 | Standalone UPDATE in both write modes | Updating another column retains 'legacy'; assigning DEFAULT uses 'current' where the catalog exposes it, while the other row retains 'legacy'. Assert the GPU writer for each mode. |

Scenarios 1–6 share one table history. A mixed MERGE covers 7–9 in both write modes. A separate insert-only MERGE exercises Spark’s append rewrite.

</details>

How this PR works

1. Write Parquet metadata

GpuSparkWrite.dataWriterSparkTypeFor() converts the actual write schema with GpuTypeToSparkType and the version-specific IcebergWriteDefaultAccessor. For each field, WriteDefaultAccessor.withWriteDefault() copies the initial default through withExistenceDefaultValue() and the write default through withCurrentDefaultValue(), when present. The values become SQL literals in Spark StructField metadata; timestamp-with-zone literals preserve the instant across daylight-saving overlaps. Defaults absent from the write schema remain absent, even if the table schema declares them.

The existing GpuParquetWriter.tableWriter obtains Spark schema JSON metadata from ParquetWriteSupport.init(conf), passes it to ParquetWriterOptions.withMetadata(), and creates the writer with Table.writeParquetChunked(). These existing cuDF interfaces persist the footer metadata without native cuDF or JNI changes.

2. Write the materialized column

For the omitted-column INSERT path verified with Spark 4.1.1 and Iceberg 1.11.0, Iceberg's TypeToSparkType.struct() exposes the table's write default in Spark's current-default metadata. Spark's Analyzer.ResolveOutputRelation then calls TableOutputResolver.resolveOutputColumns() with default-value support enabled. When reorderColumnsByName() finds an omitted column, ResolveDefaultColumns.getDefaultValueExprOrNullLit() resolves its default expression, and the analyzer inserts a Project. For example, omitting status with write default 'current' produces the equivalent of SELECT id, 'current' AS status FROM input.

The projection generates the physical column during execution, before the batch reaches the Parquet writer. If the projection runs on the GPU, GpuLiteral.columnarEval() expands the literal to a column with the batch's row count through GpuExpressionsUtils.resolveColumnVector() and GpuColumnVector.from(scalar, numRows). The existing writer writes that column like any other input column. An explicit NULL already matches the target column and is preserved. If Spark cannot resolve the omitted column, analysis fails (for example, with CANNOT_FIND_DATA) and GPU execution preserves that behavior. This PR adds default-aware GPU eligibility checks and footer preservation; column materialization uses the existing Spark/RAPIDS execution path.

Write performance

Measured GPU Iceberg v3 appends on one NVIDIA L4 with Spark 4.1.1, Iceberg 1.11.0, Java 17, a local Hadoop catalog and Snappy. Each append committed 262,144 rows with 16 columns to four Parquet files. The comparison used the upstream 97f4924de writer and the PR writer (production sources identical at e064dd79e and f1f6d87cc), with the same native libraries.

| Actual writer schema | Main append, ms | PR append, ms | Driver schema conversion, µs (main → PR) | Footer bytes/file (main → PR) |
|---|---:|---:|---:|---:|
| No defaults | 330.1 [321.2–343.2] | 325.0 [316.9–347.3] | 4.03 → 3.74 | 2,851 → 2,851 |
| Four string fields with initial and write defaults | 326.8 [318.8–341.1] | 329.7 [317.5–340.2] | 4.02 → 6.59 | 2,851 → 3,063 |

With four default pairs, median driver conversion increased by 2.56 µs and each footer grew by 212 bytes. Median append latency increased by 2.9 ms (+0.9%). The middle 50% of timings overlapped, and the paired JVM runs varied in both directions.

Append times are medians [IQR] including planning and the Iceberg commit. Four adjacent main/PR pairs alternated which version ran first. Each Spark JVM warmed up with four appends per schema, then timed six per schema (24 measurements per cell). The driver conversion was timed separately in warmed JVMs. Iceberg 1.11.0 strips defaults during ordinary SQL write-schema conversion, so the second workload used a benchmark catalog to pass four default pairs to the production writer. Both versions used the same fixture. We checked the GPU append plans and every file’s physical footer.

Validation

  • Review follow-up: add two standalone UPDATE cases (COW/MOR), bringing the focused suite to 12 cases. The 10 changed or affected DML cases passed on Spark 4.1.1 / Iceberg 1.11.0 with both ordinary jar loading and ICEBERG_EXTRA_CLASSPATH, using six workers. MERGE parameters now assert their exact GPU writers, omitted-column INSERT outcomes are compared independently, and hash-only checks avoid Parquet decoding.

  • All 8 tests in GpuSparkWriteSuite passed, including the real GPU Parquet writer regression for distinct supplied defaults and field IDs. The final run compiled the suite with Scala 2.13.18 and used the repository's process-isolated runner against reactor-built dependencies and matching bundled JNI libraries.
  • Before the review follow-up, consolidated the focused integration suite from 20 cases to 10 (50%). On Spark 4.1.1 / Iceberg 1.11.0, the compact suite passed on Hadoop with ordinary jar loading and with ICEBERG_EXTRA_CLASSPATH. Lakekeeper 0.13.9 with Iceberg 1.11.0 passed all 10 cases on each of Spark 4.0.4 and 4.1.1, with zero skips.

  • Spark 4.0.4 / Iceberg 1.10.1, Hadoop: all 10 passed, including the omitted-column error branch. Repeating the evolution test against the earlier table-default lookup failed the CPU/GPU footer comparison, although both writers stored the same physical values.

  • Before the review follow-up, JaCoCo comparison on Spark 4.1.1, same JVM classes and system classpath, OOM injection disabled: the 20-case baseline and 10-case suite each covered 703 lines and 112 branches in the PR’s eight executable JVM source files. No source line lost covered instructions or branches.

  • Both Spark 4.0.4 and 4.1.1 package builds and all 22 focused unit tests passed before this Python-only consolidation.
  • Codex assisted Chong Gao 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: res-life Review duration: 5383m
    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 #17100"
    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%