Skip to content

fix(variant): preserve nulls for missing shredded list indexes - #11052

Closed
emecii wants to merge 2 commits into
apache:mainfrom
emecii:fix/variant-get-shredded-list-null-11050
Closed

emecii wants to merge 2 commits into
apache:mainfrom
emecii:fix/variant-get-shredded-list-null-11050

Conversation

@emecii

@emecii emecii commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

An out-of-bounds list lookup and a present Variant null both produce null child columns after take. Without preserving index validity separately, shredded input turns missing list positions into valid Variant nulls, unlike unshredded input.

What changes are included in this PR?

  • Carry the list index validity mask through shredded path traversal.
  • Apply that mask to the output while preserving explicit Variant null elements as valid values.
  • Update list-like coverage and add a regression test distinguishing an empty list, an explicit null element, and a typed element.

Are these changes tested?

Yes.

  • cargo test -p parquet-variant-compute
  • cargo clippy -p parquet-variant-compute --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check

Are there any user-facing changes?

Yes. variant_get now returns an Arrow null for an out-of-bounds lookup on shredded list-like values, matching unshredded input semantics.

AI usage

OpenAI Codex assisted with investigating the issue, generating the implementation and tests, running the listed local validation, and drafting this PR description.

@github-actions github-actions Bot added the parquet-variant parquet-variant* crates label Sep 10, 2026
@sdf-jkl

sdf-jkl commented Sep 10, 2026

Copy link
Copy Markdown
Member

I'll take a look tomorrow

@sdf-jkl

sdf-jkl commented Sep 15, 2026

Copy link
Copy Markdown
Member

Thanks @emecii. The PR looks good directionally, but I want to be more thorough with performance and memory footprint of Variant.

I will file an EPIC for tracking/filing Variant benchmarks.

@sdf-jkl

sdf-jkl commented Sep 15, 2026

Copy link
Copy Markdown
Member

Filed here - #11101

@emecii

emecii commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

For #11052, I can add a benchmark-only PR covering list-index validity: in-bounds/missing indexes, explicit nulls, nested lists, List/ListView, sliced inputs, typed/Variant outputs, and a struct-only control. I'd compare identical fixtures on base/head and measure allocations separately from runtime.

An initial local allocation probe shows additional bitmap-union costs on nullable paths, so shared-buffer cloning alone doesn't establish the cost. Does this cover the evidence you'd like before merging the fix?

@sdf-jkl

sdf-jkl commented Sep 21, 2026

Copy link
Copy Markdown
Member

That'd be great @emecii. Thanks

@emecii

emecii commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Opened benchmark-only #11193: 104 deterministic cases with separate timing/allocation measurements; 367 tests, Clippy and formatting pass.

The 64-row all-OOB Int64 case produces equivalent output but adds 5 allocations / 224 requested bytes. A reverse-order repeat measured 1.000 → 1.238 µs (~24% slower locally, Apple M4/Rust 1.98). Other cases correct baseline validity bugs, so their timings compare different output semantics. Full confidence intervals, controls and reproduction commands are in #11193; no production optimization is bundled.

sdf-jkl pushed a commit to sdf-jkl/arrow-rs that referenced this pull request Oct 2, 2026
# Which issue does this PR close?

Related to apache#11101 and apache#11052.

# Rationale for this change

Add a small benchmark for `variant_get` list-index lookup when some rows
are empty lists.

# What changes are included in this PR?

Two benchmark functions in the existing `variant_kernels` target,
following the nearby cases. The first builds 8,192 rows alternating
empty and two-element integer lists, then looks up index zero with
Variant output. The same fixture is timed unshredded and shredded as a
List of Int64. Fixture construction, shredding, and path setup are
outside timing; options cloning and output destruction are included.

The second restores the previously regressing small case: 64 one-element
`[1]` lists shredded as List<Int64>, index 9 (all out of bounds), and
Int64 output. It checks that all 64 results are null before timing. The
benchmark name is `variant_get_list_index_all_oob_int64_64_rows`.

# Are these changes tested?

- `cargo bench --locked -p parquet-variant-compute --bench
variant_kernels -- variant_get_list_index --test`: all three cases pass.
- Focused Criterion runs completed the mixed-list cases and the all-OOB
case (50 samples, 1 s warm-up, 3 s measurement).
- `cargo test --locked -p parquet-variant-compute`: 367 unit tests and
13 doc tests passed for the previous revision; this benchmark-only
follow-up was validated with the benchmark smoke run, Criterion, Clippy,
and formatting.
- `cargo clippy --locked -p parquet-variant-compute --all-targets
--all-features -- -D warnings`
- `cargo fmt --all -- --check`, `git diff --check`, and the repository
spelling check with typos 1.37.0 pass.

The benchmark runs on the existing baseline without asserting the
missing-index validity behavior that apache#11052 fixes. Unshredded and
shredded outputs currently differ in validity on empty rows, so these
timings do not establish an equivalent-output speedup or the cost of
that correctness fix. The earlier ~24% overhead observed in the separate
64-row all-OOB Int64 case remains unresolved; adding its benchmark does
not change that result.

# Are there any user-facing changes?

No. This only adds a benchmark; production code and dependencies are
unchanged.

# AI usage

OpenAI Codex generated this benchmark revision, ran the validation, and
drafted this description and review reply.
@sdf-jkl

sdf-jkl commented Oct 2, 2026

Copy link
Copy Markdown
Member

@emecii could you merge the latest changes from main so I can run the new benchmark here? We'll move from there

@emecii

emecii commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (6d44c7c5) in 64240f600c2aa2e911b2a5e0f7c08d211d67566d, including all three list-index benchmark cases from #11193. The correctness patch is unchanged. On Rust 1.99.0, all 370 crate tests, 15 doc tests, three benchmark smoke cases, strict Clippy, and formatting passed. This enables benchmarking here; the earlier ~24% regression remains unresolved. OpenAI Codex performed the merge and validation and drafted this reply.

@sdf-jkl

sdf-jkl commented Oct 3, 2026

Copy link
Copy Markdown
Member

run benchmark variant_kernels

env:
BENCH_FILTER: "^variant_get_list_index"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing fix/variant-get-shredded-list-null-11050 (64240f6) to 6d44c7c (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_list_index
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing fix/variant-get-shredded-list-null-11050 (64240f6) to 6d44c7c (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_list_index
shards: 1
Details
group                                           base                                   changed
-----                                           ----                                   -------
variant_get_list_index_all_oob_int64_64_rows    1.00  1771.5±41.99ns        ? ?/sec    1.21      2.1±0.07µs        ? ?/sec
variant_get_list_index_shredded                 1.00     45.6±1.57µs        ? ?/sec    1.00     45.7±1.60µs        ? ?/sec
variant_get_list_index_unshredded               1.04  1031.4±13.98µs        ? ?/sec    1.00   992.5±14.29µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-4ffvevr1-a4e5654c-8f6d

Instance: c4a-highcpu-48 (12 vCPU / 65 GiB)

uname:

Linux bench-c5971562060-3049-nbzbj 6.12.94+ #1 SMP Wed Aug 19 07:47:20 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):                                  48
On-line CPU(s) list:                     0-47
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     48
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:                               3 MiB (48 instances)
L1i cache:                               3 MiB (48 instances)
L2 cache:                                96 MiB (48 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-47
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 40.0s
Peak memory 311.1 MiB
Avg memory 18.6 MiB
CPU user 35.7s
CPU sys 0.1s
Peak spill 0 B

branch

Metric Value
Wall time 35.0s
Peak memory 371.3 MiB
Avg memory 22.6 MiB
CPU user 30.9s
CPU sys 0.1s
Peak spill 0 B

File an issue against this benchmark runner

@sdf-jkl

sdf-jkl commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks @emecii everything looks great!

We could optimize all OOB case by adding a fast-path to avoid using take if the take_indices array is empty.

@sdf-jkl

sdf-jkl commented Nov 2, 2026

Copy link
Copy Markdown
Member

@emecii do you have the bandwidth to make the update?

@sdf-jkl

sdf-jkl commented Nov 5, 2026

Copy link
Copy Markdown
Member

@emecii could you also enable CI on your fork?

@sdf-jkl

sdf-jkl commented Nov 12, 2026

Copy link
Copy Markdown
Member

@Jefffrey -- @emecii seems to be busy and can't enable the CI on his fork. Can you move this to MQ without the fork CI pass?

@Jefffrey

Copy link
Copy Markdown
Contributor

@Jefffrey -- @emecii seems to be busy and can't enable the CI on his fork. Can you move this to MQ without the fork CI pass?

no dont think im able to; i think i have the same level of github perms as you, only infra has admin

@sdf-jkl

sdf-jkl commented Nov 13, 2026

Copy link
Copy Markdown
Member

I'll open a new PR using @emecii commits then

Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Nov 13, 2026
…e#12224)

# Which issue does this PR close?

- Closes apache#11050.
- Supersedes apache#11052.

# Rationale for this change

This carries @emecii's fix from apache#11052, which was approved but has had
no activity since October. The commit is unchanged and keeps their
authorship, rebased onto current `main`.

An out-of-bounds list lookup and a present Variant null both produce
null child columns after `take`. Without tracking index validity
separately, shredded input turns missing list positions into valid
Variant nulls, unlike unshredded input.

# What changes are included in this PR?

- Carry the list index validity mask through shredded path traversal
(@emecii's commit).
- Apply that mask to the output while preserving explicit Variant null
elements as valid values.
- Regression test distinguishing an empty list, an explicit null
element, and a typed element.
- When no row has the requested index in bounds, the path step is
`Missing` and `take` is skipped. This addresses the all-out-of-bounds
slowdown measured in apache#11052. `value` is not consulted because arrays are
never stored there when `typed_value` is a list, which matches Spark
(`SparkShreddingUtils` returns null for an out-of-bounds index without
reading `value`).
- For the same reason, the two existing no-match exits of the list index
step (elements are not a struct, or elements hold no values) now also
return `Missing` instead of falling back to `value` row by row. For
valid data this changes no results, since `value` can only hold
non-arrays there, which index to NULL.
- A `Missing` path step with no `as_type` now returns an all-null
`VariantArray`, as documented on `GetOptions::as_type`, instead of a
`NullArray`.

# Are these changes tested?

Yes. `test_shredded_list_out_of_bounds_is_null` distinguishes an empty
list, an explicit null element, a typed element, and a non-list row, for
both a mixed and an all-out-of-bounds index. The existing missing-path
Variant output test now also runs without `as_type`.

`variant_get_list_index_all_oob_int64_64_rows` goes from 1.32 µs to 0.47
µs locally compared to apache#11052. The other `variant_get_list_index`
benchmarks are within noise.

# Are there any significant user-facing changes?

`variant_get` without `as_type` now returns an all-null `VariantArray`
instead of a `NullArray` when the path cannot match a shredded column,
for example a field that does not exist on a fully shredded object.

# AI usage disclosure

The original change was written with OpenAI Codex (see apache#11052). Claude
Code carried the commit over and drafted this description.

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

Co-authored-by: Yifan Chen <[email protected]>

---------

Co-authored-by: Yifan Chen <[email protected]>
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

parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] variant_get returns Variant null instead of SQL NULL for out-of-bounds access on shredded lists

4 participants