Skip to content

fix: return errors for missing Variant metadata field names - #11106

Merged
sdf-jkl merged 5 commits into
apache:mainfrom
peterxcli:fix/variant-missing-metadata
Nov 24, 2026
Merged

sdf-jkl merged 5 commits into
apache:mainfrom
peterxcli:fix/variant-missing-metadata

Conversation

@peterxcli

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #11069.

unshred_variant panics when a present shredded field name is missing from metadata.

What changes are included in this PR?

Add VariantBuilderExt::try_append_value and propagate builder errors through unshredding, including nested objects and list elements.

Are these changes tested?

Regression tests cover missing metadata names, absent fields, and parent nulls. Variant crate tests, formatting, and Clippy pass.

Are there any user-facing changes?

Missing metadata field names now produce ArrowError instead of a panic. Existing append_value APIs remain available.

@osipovartem

Copy link
Copy Markdown
Contributor

I had opened an overlapping fallible-builder PR and have closed it in favor of this one. During independent review, we found a separate ObjectState rollback bug when a fallible overwrite fails; the standalone fix and tests are in #11403. The patches touch different parts of object.rs and can land independently.

osipovartem added a commit to Embucket/arrow-rs that referenced this pull request Oct 23, 2026
)

### Why
`ObjectBuilder` updates its field-offset map before appending a value.
With duplicate-key validation enabled, rejecting a duplicate can leave
the map changed. With validation disabled, a failed fallible overwrite
truncates bytes but leaves the previous offset unrestored. Continuing to
build the object can then produce an invalid value.

### Change
Reject validated duplicates before mutation and restore the previous
offset when a permitted overwrite fails. The default non-validating path
keeps its existing `fields.insert` fast path. Add regression tests that
continue building after each error. This is independent of the fallible
trait API in apache#11106; it is the unique correction extracted from
superseded apache#11401.

### Validation
- `cargo +1.98.1 test -p parquet-variant --lib`: 176 passed.
- Formatting and `cargo +1.98.1 clippy -p parquet-variant --lib` pass
(installed 1.98.1 reports the repo's newer lint as unknown).
- Focused short Criterion runs showed no repeatable regression, but WSL
measurements were noisy; the default insert path is unchanged.
- Independent read-only review covered correctness, regressions,
performance, API compatibility, and tests; approved with no blockers.
Surajsuthar pushed a commit to Surajsuthar/arrow-rs that referenced this pull request Nov 5, 2026
# Which issue does this PR close?

- Part of apache#11101.

# Rationale for this change

No benchmark calls `unshred_variant`, directly or through `variant_get`,
so changes to this kernel can't be compared on the existing suite.
apache#11106 is a current example: it changes how nested fallback values are
written, and nothing measures that path.

# What changes are included in this PR?

Adds seven `unshred_variant` benchmarks to `variant_kernels`, each
processing 8,192 rows. The cases are chosen so that a change to one path
should not move the others.

| Benchmark | Rows | What it isolates | ns/row |
|---|---|---|---:|
| `unshred_variant_primitive` | Int64, fully typed | Row loop and
metadata validation | 41 |
| `unshred_variant_object` | `{first, last, age}`, fully typed | Object
construction with a small dictionary | 406 |
| `unshred_variant_partial_object` | 5 of 15 fields typed, 10 leftover,
one sorted 300-name dictionary shared by all rows | Merging typed and
leftover fields, binary search name lookups | 3,354 |
| `unshred_variant_partial_object_unsorted_metadata` | Same documents,
unsorted dictionary | Linear scan name lookups | 18,020 |
| `unshred_variant_nested_fallback` | Field shredded as Int64 holding an
object 5 levels deep with 2 fields per object | Rebuilding a nested
fallback value | 10,223 |
| `unshred_variant_list` | `List<Float64>`, 0 to 100 elements per row |
Per-element list cost | 775 |
| `unshred_variant_list_of_objects` | 8 typed objects per row | Objects
in lists, repeated name lookups within a row | 1,589 |

Times are medians of 3 Criterion runs on one workstation, to show scale
only.

Left out on purpose: the unshredded fast path, because it is a
constant-time clone, and other primitive types and metadata encodings,
which stayed within about 12 ns and about 5% of these cases in ad hoc
runs.

The partial object schema and the JSON-to-variant setup move into small
helpers shared with existing benchmarks, and the object fixture can now
take its dictionary order. The existing benchmarks keep their names and
workloads.

# Are these changes tested?

This is benchmark-only. As a check that the suite catches what it is
for, applying the source changes from apache#11106 moves
`unshred_variant_nested_fallback` from 10,223 to 18,917 ns per row
(1.85x), while the other six cases stay between 0.99x and 1.03x.

# Are there any significant user-facing changes?

No, only benchmark code changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
@sdf-jkl

sdf-jkl commented Nov 5, 2026

Copy link
Copy Markdown
Member

@peterxcli I added a bench for unshred_variant in #12079

Could you please update this branch 🙏

@Rich-T-kid Rich-T-kid added the bug Squash those bugs label Nov 16, 2026
…-metadata

Resolve the conflict with apache#12092, which removed `TopLevelRowSink`, and
switch the tests from `StructArrayBuilder` to `StructArrayAssembler`,
which moved to arrow-array in apache#10636.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sdf-jkl

sdf-jkl commented Nov 20, 2026

Copy link
Copy Markdown
Member

run benchmark unshred_variant

@adriangbot

This comment was marked as outdated.

@sdf-jkl

sdf-jkl commented Nov 20, 2026

Copy link
Copy Markdown
Member

run benchmark variant_kernels
env:
BENCH_FILTER: "unshred_variant"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing fix/variant-missing-metadata (8f1adb8) to 1b42833 (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: unshred_variant
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

This comment was marked as outdated.

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing fix/variant-missing-metadata (8f1adb8) to 1b42833 (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: unshred_variant
shards: 1

Details
group                                               base                                   changed
-----                                               ----                                   -------
unshred_variant_list                                1.00     10.1±0.05ms        ? ?/sec    1.01     10.2±0.04ms        ? ?/sec
unshred_variant_list_of_objects                     1.02     22.9±0.19ms        ? ?/sec    1.00     22.4±0.08ms        ? ?/sec
unshred_variant_nested_fallback                     1.00    152.3±0.17ms        ? ?/sec    1.85    282.1±1.70ms        ? ?/sec
unshred_variant_object                              1.02      5.5±0.05ms        ? ?/sec    1.00      5.4±0.03ms        ? ?/sec
unshred_variant_partial_object                      1.00     44.4±0.13ms        ? ?/sec    1.00     44.5±0.69ms        ? ?/sec
unshred_variant_partial_object_unsorted_metadata    1.00    198.3±1.88ms        ? ?/sec    1.02    202.2±0.98ms        ? ?/sec
unshred_variant_primitive                           1.02    431.5±2.71µs        ? ?/sec    1.00    423.5±3.15µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-1ucnhyuy-1723d824-228s

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c7053411156-5569-xxgzs 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 115.0s
Peak memory 374.7 MiB
Avg memory 54.6 MiB
CPU user 108.6s
CPU sys 0.2s
Peak spill 0 B

branch

Metric Value
Wall time 120.0s
Peak memory 428.9 MiB
Avg memory 55.2 MiB
CPU user 118.0s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

@sdf-jkl

sdf-jkl commented Nov 23, 2026

Copy link
Copy Markdown
Member
group                                               base                                   changed
-----                                               ----                                   -------
...
unshred_variant_nested_fallback                     1.00    152.3±0.17ms        ? ?/sec    1.85    282.1±1.70ms        ? ?/sec
...

Is the only one regressing due to nested structs child revalidation via iter_try()

Each remaining row reaches a different conversion to the fallible append.
The removed rows (`{"a":null}`, nested, list, masked rows, and the
nested/list absent-field cases) failed on the same reverted conversions
as a kept row, or on none of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sdf-jkl

sdf-jkl commented Nov 23, 2026

Copy link
Copy Markdown
Member

@peterxcli I took the liberty of trimming the tests to push this forward 🙏

@sdf-jkl sdf-jkl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @peterxcli this was much needed downstream

@sdf-jkl
sdf-jkl enabled auto-merge November 24, 2026 00:07
@sdf-jkl
sdf-jkl added this pull request to the merge queue Nov 24, 2026
Merged via the queue into apache:main with commit a5c9ea9 Nov 24, 2026
21 of 22 checks passed
@peterxcli
peterxcli deleted the fix/variant-missing-metadata branch November 24, 2026 03:50
@sdf-jkl

sdf-jkl commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks again @peterxcli 🙌

@peterxcli

Copy link
Copy Markdown
Member Author

Thanks @sdf-jkl for driving this to completion 🚀

mbutrovich pushed a commit to mbutrovich/arrow-rs that referenced this pull request Nov 24, 2026
… and lists (apache#12430)

# Which issue does this PR close?

- Follow-up to apache#11106, which made `unshred_variant_nested_fallback`
1.85x slower on the benchmark runner.

# Rationale for this change

`VariantObject::iter_try` and `VariantList::iter_try` call
`with_full_validation()` on every child, and
`ValueBuilder::try_append_variant` then recurses into each child object
or list and calls `iter_try` again. A value nested `d` levels deep is
fully validated about `d` times. With apache#11106, `unshred_variant` takes
this path for fallback values, even though it has already fully
validated each value with `Variant::try_new_with_metadata`.

Full validation of an object or list recursively validates all of its
children, so every child of a validated value is already valid. The
accessors build each child with only shallow checks, so the child loses
that fact and gets validated again. This is the same problem apache#10879
fixed for metadata dictionary entries.

# What changes are included in this PR?

`VariantObject` and `VariantList` mark a child as fully validated when
they build it from a fully validated parent. `with_full_validation` on
such a child returns immediately, so `iter_try`, `try_field` and
`try_get` no longer re-validate subtrees. Children of unvalidated
parents are built and validated as before.

This conflicts with apache#12309 from @cetra3, which rewrites the code that
builds child values. The resolution adds the same one-line call where
apache#12309 builds children, and I am happy to do it in whichever PR lands
second.

# Are these changes tested?

`test_children_inherit_full_validation` checks that the fields and list
elements of a validated value report `is_fully_validated()`, and that
those of an unvalidated value do not. It fails if either the object or
the list half of the change is removed.

`unshred_variant_nested_fallback` from `variant_kernels` (local x86,
`codegen-units=1`):

| | time |
|---|---|
| before apache#11106 | 89.7 ms |
| apache#11106 | 159.8 ms |
| apache#11106 and this PR | 87.1 ms |

Removing the `with_full_validation()` calls from both `iter_try`
implementations entirely gives about the same time (88.8 ms), so the
re-validation accounts for the whole regression.

# Are there any significant user-facing changes?

Children returned by the accessors of a fully validated `VariantObject`
or `VariantList` (`field`, `get`, `iter` and their fallible versions)
now report `is_fully_validated() == true`. They reported `false` before,
although they were valid. No public API changes.

# AI usage disclosure

Claude Code helped find the cause, write the change and test, and run
the benchmarks. I reviewed the change and the measurements.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] unshred_variant panics when a shredded field name is absent from metadata

5 participants