Skip to content

feat(arrow): read shredded variant columns - #3683

Open
swanandx wants to merge 2 commits into
apache:mainfrom
swanandx:read-shredded-variants
Open

swanandx wants to merge 2 commits into
apache:mainfrom
swanandx:read-shredded-variants

Conversation

@swanandx

Copy link
Copy Markdown
Contributor

Merge typed_value back into value with arrow-rs unshred_variant. Also skip variant leaves in the INT96 coercion, and skip null struct rows when a required variant is unshredded.

Which issue does this PR close?

What changes are included in this PR?

The reader can now read shredded variant columns. It uses arrow-rs unshred_variant to merge typed_value back into value. The caller gets the same rows as from an unshredded column.

Before this PR, two more cases stopped the read of a shredded file with an error. This PR also corrects these cases:

  • A shredded timestamp with nanosecond precision. The INT96 coercion now ignores the leaves of a variant.
  • A required variant in an optional struct, when a row of the struct is null.

This PR adds the dependency parquet-variant-compute.

Are these changes tested?

Yes:

  • Unit tests shred variants with arrow-rs, write a Parquet file, and read the file again.
  • On my computer, I read a file from iceberg-java 1.12 that has all shredded types. All rows are correct.
  • On my computer, all 29 tests in TestVariantShredding pass with the Comet Iceberg 1.11 / Spark 4.1 suite. Without this PR, 7 of these tests stop with FeatureUnsupported.

AI Disclosure

I used Claude Code to write the code, the tests. I read the full diff and did the tests that this description gives.

Examine these areas:

  • The correct result depends on unshred_variant. arrow-rs marks its variant support as experimental.
  • unshred_variant ignores unknown fields in nested shredded groups.

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @swanandx for picking this up so soon after #2880. I updated apache/datafusion-comet#7575 to run this change through Comet's native Iceberg scan, backported to arrow 59, and added a CometIcebergNativeSuite test that reads Spark-shredded files natively. Locally, that test and the suite's other variant tests pass, and so do all 29 of Iceberg 1.11's TestVariantShredding tests, where 7 fail with #2880 alone.

Comment thread crates/iceberg/src/arrow/schema.rs Resolved
children: &[ChildPlan],
parent_nulls: Option<&arrow_buffer::NullBuffer>,
) -> Result<StructArray> {
let nulls = arrow_buffer::NullBuffer::union(parent_nulls, source.nulls());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This union now runs for every struct the transformer promotes. When a struct and one of its ancestors both have nulls, NullBuffer::union allocates a new bitmap for each batch, even when no variant is below the struct. Only the Unshred arm reads parent_nulls. Could we compute the union only when a child needs it? One way is a flag on PromotePlan::Struct, set when the plan is built if a descendant is Unshred.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with an unshred_below flag, set at plan build.

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @swanandx for running this against the full TestVariantShredding suite. Agreed with @mbutrovich on both of his threads: an end-to-end read with value omitted plus a shredded map value, and computing the NullBuffer::union only when a descendant is Unshred. His review is the gate here, so I'd like his sign-off before this goes in. My two comments are small ones on the unshred error.

Merge `typed_value` back into `value` with arrow-rs `unshred_variant`.
Also skip variant leaves in the INT96 coercion, and skip null struct rows
when a required variant is unshredded.

Signed-off-by: Swanand Mulay <[email protected]>
Compute the parent null union only for structs with a shredded variant
below them. Attach the arrow error as the source of the unshred error.
Add read tests for a shredded variant with no `value` and for one in a
map value.

This branch has not been deployed

No deployments
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.

Read shredded variant columns from Parquet

3 participants