This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-12092-2553a2be695299b6c18876cbe511cb642fbe5963 in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit 0727b45d3124108d3495995955f1ac1d28086705 Author: Kosta Tarasov <[email protected]> AuthorDate: Sat Nov 14 02:47:12 2026 +0000 [Variant] Remove `TopLevelRowSink` (#12092) # Which issue does this PR close? No issue. This cleans up a wrapper added in #10320. # Rationale for this change `unshred_variant` wraps its top-level builder in `TopLevelRowSink`, whose only job is to turn `append_null` into `Variant::Null`, because a physical NULL cannot go in the non-nullable output `value` column. That takes about 30 lines of forwarding code to override one method. The method it overrides, `VariantValueArrayBuilderExt::append_null`, has no other callers in the workspace. `shred_variant` only uses the ext to start an object, and writes its nulls through the inherent `VariantValueArrayBuilder::append_null`. So the behaviour can live on the builder itself. # What changes are included in this PR? - `VariantValueArrayBuilderExt::append_null` now appends `Variant::Null`. - `TopLevelRowSink` is removed, and `unshred_variant` passes the ext directly to the row builders. `unshred_variant` output does not change. Missing top-level rows still become `Variant::Null`, and nested builders keep their own `append_null` behaviour: list elements become `Variant::Null` and missing object fields are omitted. # Are these changes tested? Covered by existing tests, which fail if the ext writes a physical NULL: `test_unshred_missing_top_level_value_becomes_variant_null`, `test_unshred_missing_row_for_decimal_timestamp_object_list`, `test_unshred_value_only_with_unmasked_nulls_materializes_variant_null`, and `variant_integration` case 129. # Are there any significant user-facing changes? `VariantValueArrayBuilder::builder_ext(..).append_null()` now writes `Variant::Null` instead of a physical NULL. Callers building the `value` column of a shredded variant should call the inherent `VariantValueArrayBuilder::append_null`, which is unchanged. No signatures change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]> --- parquet-variant-compute/src/unshred_variant.rs | 42 +++------------------- .../src/variant_array_builder.rs | 4 ++- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/parquet-variant-compute/src/unshred_variant.rs b/parquet-variant-compute/src/unshred_variant.rs index cfcbd56171..6a8255ed37 100644 --- a/parquet-variant-compute/src/unshred_variant.rs +++ b/parquet-variant-compute/src/unshred_variant.rs @@ -22,8 +22,8 @@ use arrow::temporal_conversions::time64us_to_time; use chrono::{DateTime, Utc}; use indexmap::IndexMap; use parquet_variant::{ - ListBuilder, ObjectBuilder, ObjectFieldBuilder, Variant, VariantBuilderExt, VariantDecimal4, - VariantDecimal8, VariantDecimal16, VariantDecimalType, VariantMetadata, + ObjectFieldBuilder, Variant, VariantBuilderExt, VariantDecimal4, VariantDecimal8, + VariantDecimal16, VariantDecimalType, VariantMetadata, }; use std::marker::PhantomData; use std::sync::Arc; @@ -53,7 +53,7 @@ pub fn unshred_variant(array: &VariantArray) -> Result<VariantArray> { // Already unshredded: no data movement needed, but the output must annotate `value` as // non-nullable per the spec. Inputs whose value-nulls are not all masked by the parent null // buffer (spec-invalid "missing" rows) cannot be re-annotated and fall through to the row - // loop below, whose top-level sink materializes `Variant::Null` for such rows. + // loop below, whose top-level builder materializes `Variant::Null` for such rows. if typed_value_col.is_none() { if value_field_is_non_nullable(array) { return Ok(array.clone()); @@ -83,8 +83,8 @@ pub fn unshred_variant(array: &VariantArray) -> Result<VariantArray> { ) })?; let metadata = VariantMetadata::try_new(metadata_bytes)?; - let mut row_sink = TopLevelRowSink(value_builder.builder_ext(&metadata)); - row_builder.append_row(&mut row_sink, &metadata, i)?; + let mut value_builder = value_builder.builder_ext(&metadata); + row_builder.append_row(&mut value_builder, &metadata, i)?; } } @@ -112,38 +112,6 @@ fn value_nulls_are_masked(value: &ArrayRef, parent_nulls: Option<&NullBuffer>) - .is_some_and(|(parent, value_nulls)| parent.contains(value_nulls)) } -/// Wraps the sink that every top-level row is appended into. The row builders signal a missing -/// value (value and typed_value both NULL) by calling `append_null`, and this wrapper gives that -/// signal its top-level meaning: `Variant::Null`, because the non-nullable output `value` column -/// cannot hold a physical NULL. Array-level NULL rows are appended before the sink is built, so -/// they never reach it. Nested builders created via `try_new_object`/`try_new_list` are returned -/// unwrapped, so nested missing values keep their own semantics, e.g. [`ObjectFieldBuilder`] -/// omits the field. -struct TopLevelRowSink<B>(B); - -impl<B: VariantBuilderExt> VariantBuilderExt for TopLevelRowSink<B> { - type State<'a> - = B::State<'a> - where - Self: 'a; - - fn append_null(&mut self) { - self.0.append_value(Variant::Null); - } - - fn append_value<'m, 'v>(&mut self, value: impl Into<Variant<'m, 'v>>) { - self.0.append_value(value); - } - - fn try_new_list(&mut self) -> Result<ListBuilder<'_, Self::State<'_>>> { - self.0.try_new_list() - } - - fn try_new_object(&mut self) -> Result<ObjectBuilder<'_, Self::State<'_>>> { - self.0.try_new_object() - } -} - /// Row builder for converting shredded VariantArray rows back to unshredded form enum UnshredVariantRowBuilder<'a> { PrimitiveInt8(UnshredPrimitiveRowBuilder<'a, PrimitiveArray<Int8Type>>), diff --git a/parquet-variant-compute/src/variant_array_builder.rs b/parquet-variant-compute/src/variant_array_builder.rs index b15bb03597..037fba90a6 100644 --- a/parquet-variant-compute/src/variant_array_builder.rs +++ b/parquet-variant-compute/src/variant_array_builder.rs @@ -426,8 +426,10 @@ impl VariantBuilderExt for VariantValueArrayBuilderExt<'_> { where Self: 'b; + /// Appending NULL produces `Variant::Null`, because the `value` column of an unshredded variant + /// is non-nullable. Use [`VariantValueArrayBuilder::append_null`] for a shredded column. fn append_null(&mut self) { - self.value_builder.append_null() + self.append_value(Variant::Null); } fn append_value<'m, 'v>(&mut self, value: impl Into<Variant<'m, 'v>>) {
