Repository navigation
Conversation
There was a problem hiding this comment.
@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))?; |
There was a problem hiding this comment.
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(|| { |
There was a problem hiding this comment.
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| { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
Which issue does this PR close?
Closes #10620.
Rationale for this change
VariantArray::try_valuereturns 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 useunshred_variantonce.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_valueremains the zero-allocation borrowed accessor and continues to reject composite typed values.