fix: fall back for shredded Variant scans on Spark 4.0#4084
Merged
mbutrovich merged 1 commit intoapache:mainfrom Apr 26, 2026
Merged
fix: fall back for shredded Variant scans on Spark 4.0#4084mbutrovich merged 1 commit intoapache:mainfrom
mbutrovich merged 1 commit intoapache:mainfrom
Conversation
Spark 4.0's PushVariantIntoScan rewrites VariantType columns into a StructType whose fields carry __VARIANT_METADATA_KEY metadata, then pushes variant_get paths down as ordinary struct field accesses. By the time CometScanRule runs, the requiredSchema looks like a normal struct of primitives, so Comet scans natively but does not honor the on-disk variant shredding layout, returning nulls for typed paths. Detect the marker via VariantMetadata.isVariantStruct in the Spark 4.0 type shim and reject those structs in CometScanTypeChecker so the scan falls back to Spark. Stop ignoring VariantShreddingSuite and ParquetVariantShreddingSuite in the 4.0.1 diff. Closes apache#2209.
mbutrovich
approved these changes
Apr 26, 2026
Contributor
mbutrovich
left a comment
There was a problem hiding this comment.
LGTM, thanks @andygrove!
andygrove
added a commit
to andygrove/datafusion-comet
that referenced
this pull request
Apr 26, 2026
Mirrors the spark-4.0 CometTypeShim helper that apache#4084 added to the scan rule. VariantMetadata.isVariantStruct exists in Spark 4.1.1 (in PushVariantIntoScan.scala) so the implementation is identical to spark-4.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #2209.
Rationale for this change
Spark 4.0's
PushVariantIntoScanoptimizer rewrites aVariantTypecolumn into aStructTypewhose fields each carry__VARIANT_METADATA_KEYmetadata, then pushesvariant_getpaths down as ordinary struct field accesses. By the timeCometScanRuleruns, therequiredSchemalooks like a normal struct of primitives, so Comet scans natively but does not honor the on-disk Parquet variant shredding layout. The result is silent data corruption: typed paths read back as nulls (or, with some shapes, a hardFAILED_READ_FILE).This is data correctness, so we need to fall back to Spark for these reads rather than continuing to ignore the suites.
What changes are included in this PR?
CometTypeShim(Spark 4.0): addisVariantStructthat delegates to Spark'sVariantMetadata.isVariantStruct, which checks for the__VARIANT_METADATA_KEYmarker on every field.CometTypeShim(Spark 3.x): stub returning false; variant shredding does not exist pre-4.0.CometScanTypeChecker.isTypeSupported: add acase s: StructType if isVariantStruct(s) => falsearm with a fallback reason, so bothauto/native_datafusionandnative_iceberg_compatscan paths fall back to Spark on shredded Variant reads.dev/diffs/4.0.1.diff: stop ignoringVariantShreddingSuiteandParquetVariantShreddingSuite.How are these changes tested?
Ran
sql/testOnly org.apache.spark.sql.VariantShreddingSuite org.apache.spark.sql.execution.datasources.parquet.ParquetVariantShreddingSuiteagainst patched Spark v4.0.1 withENABLE_COMET=true ENABLE_COMET_ONHEAP=true:COMET_PARQUET_SCAN_IMPL=auto: 13/13 pass (was 5/13).COMET_PARQUET_SCAN_IMPL=native_iceberg_compat: 13/13 pass (was 5/13).The Spark SQL test workflows already cover both scan impls on every PR, so the unignored suites give us ongoing protection against regressions.