Repository navigation
Description
Describe the bug
variant_get produces different null semantics depending on whether its input is shredded.
Looking up [0] in [] returns an Arrow-null row for unshredded input, but a valid row containing Variant::Null for shredded input.
For a lookup returning Variant:
| Input | Unshredded arrow-rs | Shredded arrow-rs | Spark |
|---|---|---|---|
[] |
SQL NULL | Variant null | SQL NULL |
[null] |
Variant null | Variant null | Variant null |
[1] |
Variant 1 |
Variant 1 |
Variant 1 |
This changes the result’s validity and can affect operations such as IS NULL and COUNT(expr).
To Reproduce
Run this test in parquet-variant-compute:
use std::sync::Arc;
use arrow::array::{ArrayRef, StringArray};
use arrow_schema::DataType;
use parquet_variant::VariantPath;
use parquet_variant_compute::{
GetOptions, VariantArray, json_to_variant, shred_variant, variant_get,
};
#[test]
fn missing_list_element_preserves_null_semantics() {
let json: ArrayRef =
Arc::new(StringArray::from(vec!["[]", "[null]", "[1]"]));
let input = json_to_variant(&json).unwrap();
let schema = DataType::new_list(DataType::Int64, true);
let shredded = shred_variant(&input, &schema).unwrap();
let options = GetOptions::new_with_path(VariantPath::from(0));
let before = variant_get(&ArrayRef::from(input), options.clone()).unwrap();
let after = variant_get(&ArrayRef::from(shredded), options).unwrap();
let before = VariantArray::try_new(&before).unwrap();
let after = VariantArray::try_new(&after).unwrap();
// Explicit Variant null is a present value.
assert!(!before.is_null(1));
assert!(!after.is_null(1));
// An out-of-bounds lookup should produce a missing result.
assert!(before.is_null(0));
assert!(after.is_null(0)); // Fails
}Found while working on #10635.
Expected behavior
An out-of-bounds lookup should return an Arrow-null row regardless of shredding. An existing element containing explicit Variant null should remain a valid row containing Variant::Null.
This matches arrow-rs’s unshredded lookup and Spark:
- Spark documents that
variant_getreturns NULL when the path does not exist. is_variant_nulldistinguishes explicit Variant null from SQL NULL.- Spark’s shredded extraction implementation explicitly returns SQL NULL when the requested index is outside the array.
Additional context
The Parquet Variant array rules permit empty arrays. The requirement that elements be present applies to existing array positions.
Parquet also specifies Variant-null recovery when a required stored value is missing. That concerns an existing required position with missing contents. The spec does not explicitly define the result of an out-of-bounds lookup; this report concerns inconsistent lookup semantics and Spark parity.
Related discussion: apache/parquet-format#519, particularly scovich’s explanation of missing values, SQL NULL, and Variant null.
The likely cause is that take_list_like_index_as_shredding_state creates null child values for an out-of-bounds index without propagating the missing index into the output’s parent validity. The resulting valid row has both children null and is interpreted as Variant null. A fix should preserve index presence while retaining the required-value recovery behavior.
AI usage: OpenAI Codex assisted with investigating this issue, generated and ran arrow-rs reproduction tests, and drafted this report. The analysis included checking the Parquet shredding specification, arrow-rs’s existing lookup behavior, and Spark’s local implementation and documentation.
Activity
emecii commentedon Sep 10, 2026
take
fix(variant): preserve nulls for missing shredded list indexes (apach…
Consolidate Variant getter and path tests (#193)