Skip to content

feat(arrow/extensions): add UnshredVariant to collapse a shredded variant array - #859

Merged
zeroshade merged 1 commit into
apache:mainfrom
nssalian:variant-unshred
Jun 23, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
nssalian:variant-unshred

Conversation

@nssalian

@nssalian nssalian commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

A shredded variant array reads back in the shredded storage layout, which shares the parquet.variant extension name with the non-shredded layout but has a different storage type. There was no way to collapse it short of decoding row by row. iceberg-go needs this at scan-projection time to read a shredded variant column identically to a non-shredded one (apache/iceberg-go#986) (PR: apache/iceberg-go#1238).

What changes are included in this PR?

  • Adds extensions.UnshredVariant(arr, mem), returning an equivalent non-shredded VariantArray. An already-non-shredded array is returned unchanged with an added reference.
  • Fixed a typo in UntypedValues()'s doc string too

Are these changes tested?

Yes. TestUnshredVariant covers scalar, list, nested object, residual fields, null vs present variant-null, and passthrough.

Are there any user-facing changes?

One new exported function. No change to existing behavior.

@nssalian
nssalian marked this pull request as ready for review June 22, 2026 17:17
@nssalian
nssalian requested a review from zeroshade as a code owner June 22, 2026 17:17
@zeroshade
zeroshade merged commit 4a540f5 into apache:main Jun 23, 2026
23 checks passed
@nssalian
nssalian deleted the variant-unshred branch June 23, 2026 16:56
zeroshade pushed a commit to apache/iceberg-go that referenced this pull request Jun 23, 2026
Closes [#986](#986).

At scan time, reassembles shredded variant columns (metadata + residual
value + typed_value) back into the plain unshredded layout, so a
shredded variant reads the same as a non-shredded one. arrow-go's
VariantArray does the per-row work. The code change is only in the
projection visitor's Variant method.

Note: This PR also bumps arrow-go to 4a540f5
(apache/arrow-go@4a540f5)
(v18.6.1-0.20260623163317-4a540f514484) to pick up `UnshredVariant`
(apache/arrow-go#859), which does the per-row
reassembly.

## Fixture based Testing

The fixtures come from
[apache/parquet-testing](https://github.com/apache/parquet-testing/tree/master/shredded_variant)
(written by Iceberg Java's TestVariantReaders). I first ran all 137
upstream cases through arrow-go to see where it stands (128 pass, 4
reject, 2 lenient, 3 spec-invalid), then committed 17 of them. These
represent one per distinct reader behaviour instead of all 137:

- 9 success cases checked against the Java golden value (array, empty
array, scalar, object with a field that falls back to the residual
value, object with no value column, nested array, null variant,
unshredded data under a shredded schema, and a multi-row column with
nulls). Compared as JSON because reassembly is valid but not
byte-identical for nested objects.
- 5 cases the reader should reject (value/typed_value conflicts,
non-object-with-shredded-fields, and a spec-invalid file).
- 3 cases where arrow-go reads something Java would reject (uint32 and
fixed_size_binary typed_value, plus one spec-invalid file it reads).
These pin the current behaviour so we notice if arrow-go changes it.

## Additional Testing

- compute.Take / FilterRecordBatch leave a shredded column alone (they
run before projection).
- rows surviving a positional delete still reassemble correctly.
- a leak check on the reassembly path.
- a Spark 4 integration test that writes a shredded table and reads it
back (checks the file is actually shredded first).

---------

Signed-off-by: Neelesh Salian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants