Skip to content

[Variant] Read composite rows with a caller-owned buffer - #11537

Open
cakeni wants to merge 3 commits into
apache:mainfrom
cakeni:feat/variant-owned-value
Open

cakeni wants to merge 3 commits into
apache:mainfrom
cakeni:feat/variant-owned-value

Conversation

@cakeni

@cakeni cakeni commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #10620.

Rationale for this change

VariantArray::try_value returns a borrowed Variant, so it cannot represent a reconstructed shredded object or list without external storage. Callers currently need to unshred an array before accessing such a value.

What changes are included in this PR?

Add try_value_with_buffer(index, &mut Vec<u8>). It reconstructs only the requested composite row using the existing unshredding kernel and returns a Variant borrowing the array's metadata and the caller-owned value buffer. Primitive and residual values use the existing borrowed path. This provides storage for composite values while preserving existing accessor and iterator signatures; repeated bulk access should still use unshred_variant once.

Are these changes tested?

Regression tests cover fully and partially shredded nested objects, all four supported list layouts, sliced arrays, missing and explicit-null values, buffer reuse, primitive borrowing, SQL-null rows, bounds, conflicting fields, and malformed metadata. A two-row test verifies that invalid metadata in another row does not prevent reading the selected row. A runnable API example documents the buffer lifetime.

Are there any significant user-facing changes?

A new additive accessor supports composite values. Existing try_value remains the zero-allocation borrowed accessor and continues to reject composite typed values.

@github-actions github-actions Bot added the parquet-variant parquet-variant* crates label Oct 13, 2026

@raghuvanshraj raghuvanshraj 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.

@cakeni thanks for picking this up.

One thing above the line-level comments: nothing calls the new accessor yet. variant_to_json (parquet-variant-compute/src/to_json.rs:44), variant_get (variant_get.rs:259,262) and VariantArrayIter::value_opt still go through try_value, so a shredded object or list still fails there with cannot materialize typed_value ... call unshred_variant first. I hit this from datafusion-variant: on a file shredded on service/status, SELECT to_json(event) errors while variant_get(event, 'service') works. Is this PR meant to be the complete fix for #10620, or are the callers planned as a follow-up?

return self.try_value(index);
}

let row = crate::unshred_variant(&self.slice(index, 1))?;

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.

Each call runs UnshredVariantRowBuilder::try_new_opt over the whole typed_value schema, then builds one row. Fine for a scalar accessor. For the batch kernels (variant_to_json, variant_get), looping this would rebuild the row builders per row; those should unshred_variant once per array, as the doc comment already suggests. Could the doc state that split explicitly: scalar path = this accessor, batch path = unshred once?

}

let row = crate::unshred_variant(&self.slice(index, 1))?;
let metadata = binary_array_value(self.metadata.as_ref(), index).ok_or_else(|| {

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.

Pairing self.metadata[index] with row.value[0] is only valid because unshred_variant returns metadata.clone() unchanged and resolves field ids against that same dictionary. Either a one-line comment naming that invariant, or read the metadata from row.metadata_column() at index 0 so the pairing cannot drift if unshred_variant ever rebuilds metadata.

"Cannot read a null Variant row".into(),
));
}
let needs_buffer = self.typed_value_column().is_some_and(|typed_value| {

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.

This is a second copy of "which typed_value types are composite"; the first is the unsupported arm in typed_value_to_variant (type_conversion.rs). Two options: call try_value first and only fall to the buffer path on its NotYetImplemented, or factor one is_composite(&DataType) helper that both sites use. Otherwise the two lists can drift.

})?;
buffer.clear();
buffer.extend_from_slice(value);
Variant::try_new(metadata, buffer)

@raghuvanshraj raghuvanshraj Nov 4, 2026 •

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.

try_value deliberately skips deep validation ("Does not do deep validation of the Variant"). The bytes here were just produced by the unshred builder. Variant::new would match try_value and skip a validation walk per row.

/// ```
///
/// # Errors
/// Returns an error for an out-of-bounds index, an array-level null row,

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.

Nit: try_value says it "does not check for nulls"; this one errors on a null row. Good behaviour, but one line stating the difference would save callers porting from try_value a surprise.

@Rich-T-kid Rich-T-kid added the enhancement New feature/addition label Nov 16, 2026

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

enhancement New feature/addition parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Support composite typed_value values in VariantArray::try_value

3 participants