Skip to content

[Variant] Track and remove native Variant compatibility workarounds after upstream fixes #5477

Description

@peterxcli

What is the problem the feature request solves?

Native Variant projection from #5407, continued by #5868, includes compatibility paths for gaps in upstream Variant compute, Spark-compatible Parquet reader policy, and older Spark Variant encodings. As of 2026-09-13, Comet main locks DataFusion 55.1.0 and Arrow/Parquet 59.3.0; #5868 currently locks DataFusion 55.0.0 and Arrow/Parquet 59.3.0. The dependency upgrade is no longer a blocker. These paths are intentionally narrow, but some perform row-by-row decoding or metadata rebuilding and should not become permanent accidentally.

This issue records exactly which code is removable after an upstream fix ships, which upstream change owns it, and which nearby code is required Comet/Spark integration and must remain.

This is maintenance follow-up for #5407 under the Native Variant epic #5438. Spark UTF-16 output cleanup is tracked separately by #5474. Unicode case-insensitive Parquet field matching (#5495) is complete through #5602. The split series in #5546 reuses that shared matcher and does not carry the original PR's Unicode guards.

Arrow-rs compute workarounds

Spark reconstruction and validation compatibility

These follow-ups cover compatibility handling added while addressing review of #5868. Canonical Arrow/Parquet behavior and Spark compatibility must remain explicit.

  • Eliminate the extra Spark byte-reconstruction pass

    • Dedicated tracker: [Variant] Remove the extra Spark byte-reconstruction pass #5978. Arrow unshredding is currently followed by rebuild_spark_variant, which reconstructs values and metadata to match Spark.
    • Preserve value-dependent integer/decimal widths, typed NaN bits, string encoding, dictionary traversal and flags, residual scalar bytes, and unshredded byte passthrough.
    • [Variant] Remove Variant UTF-16 output rewriting #5474 / SPARK-58949 cover object-key ordering only. Resolving them does not remove the other byte-compatibility requirements.
    • Remove the extra pass only when one native reconstruction path passes the existing strict Spark comparisons. Measure scan time and allocation changes; keep results in the implementing PR description.
  • Preserve typed scalar/array precedence without residual pre-rewriting

    • Dedicated tracker: [Variant] Preserve typed-value precedence without residual pre-rewriting #5980. Spark ignores a redundant scalar/array residual when typed_value is present; Comet masks it before Arrow validation.
    • The Parquet specification permits both values together only for partially shredded objects. Any shared upstream support must make the Spark compatibility policy explicit.
    • Delete the masking pass only when native reconstruction preserves typed precedence, skips ignored residual validation, and still merges and validates object residuals correctly.
  • Consolidate Spark-compatible missing-value validation

    • Dedicated tracker: [Variant] Consolidate Spark-compatible missing-value validation and errors #5977. Spark's missing required-value and invalid-state checks differ from the specification's Variant-null behavior for some missing states.
    • Preserve absent object fields, required top-level/list states, SQL NULL versus Variant null, and parent-null masking.
    • Delete duplicated prevalidation only when the replacement matches supported Spark readers. Retain Comet's conversion to MALFORMED_VARIANT.

DataFusion/Arrow reader integration workaround

  • Use Spark-compatible physical schema inference for projected Variant scans
    • Spark ignores the advisory ARROW:schema footer hint, while Arrow-rs honors it and can restore shredded leaves as Decimal256, Date64, Dictionary, or fixed-size types. Comet therefore replaces an embedded hint with physical Parquet inference for an unencrypted scan whose pruned required schema projects Variant.
    • Arrow-rs also maps physical Parquet ENUM to Binary, while Spark maps ENUM to String. Once Arrow inference has discarded that annotation, the Variant normalizer cannot distinguish ENUM from raw BINARY. Comet therefore adds back a physical-schema-derived hint that changes only ENUM leaves to Utf8 (ENUM mapping, footer rewrite). Runtime controls verify ENUM and STRING become Variant strings while unannotated BINARY remains binary.
    • All other key/value metadata, row groups, column orders, column indexes, and offset indexes are preserved. Using the pruned schema also preserves feat: Support native scans with unprojected Spark 4 VARIANT columns #5377: an unread Variant column does not activate this path. Encrypted Variant scans remain on Spark because reconstructing public FileMetaData cannot preserve arrow-rs's private decryptor state.
    • Reassessment: merged Allow specifying an arrow schema for PartitionedFile datafusion#22360 already supplies PartitionedFile.arrow_schema. Arrow's ArrowReaderOptions::with_schema suppresses advisory Arrow metadata and accepts nested Binary-to-Utf8 hints. A local check verified ENUM-to-Utf8, raw BINARY preservation, bypass of an invalid Arrow hint, and reuse of the original metadata Arc. No additional Arrow ENUM-conversion API is needed for a known full per-file schema.
    • Remaining upstream integration request: Allow deriving a Parquet file Arrow schema from metadata during lazy opening datafusion#25251. Comet learns each file's shredded layout during lazy footer loading; the current reader factory cannot return a newly derived schema/options to DataFusion's opener. Allow source-specific physical-schema policy after footer loading and before Arrow schema inference, preserving the original metadata, cache behavior and decryption state. #22360 is sufficient when that complete schema is already available before opening.
    • Parquet schema file type coercion functionality is not applied on all fields in nested schemas, only on the top-level fields datafusion#25192 covers nested table-schema coercions; it does not supply missing per-file shredded layouts or physical ENUM annotations.
    • Remove the footer reconstruction when the existing supplied-schema route can be used at Comet's lazy-open boundary. Reassess the encrypted fallback only after encryption-specific validation; preserving the metadata Arc alone is not an encrypted-scan test.

Describe the potential solution

For each checklist item:

  1. Wait for the relevant upstream behavior to merge and appear in a released dependency or reachable DataFusion reader API.
  2. Upgrade Arrow/Parquet/DataFusion through the normal dependency update.
  3. Delete only the mapped compatibility branch; do not duplicate an upstream implementation locally.
  4. Keep or adapt the existing regression tests to prove the upstream path works through Comet.
  5. Run the focused Rust Variant tests, Spark 4 Variant SQL tests, Spark 3 compilation boundary, formatting/lint, and git diff --check.

Definition of done:

Additional context

The following nearby code is not covered by the upstream fixes above:

Dependency snapshot (2026-09-13): Comet main locks DataFusion 55.1.0 and Arrow/Parquet 59.3.0; #5868 locks DataFusion 55.0.0 and Arrow/Parquet 59.3.0. Links to the original #5407 implementation describe the compatibility branches to reassess, not the current main dependency. Checked upstream-fix entries do not by themselves mean Comet's released dependency contains the fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:scanParquet scan / data readingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions