MCPcopy Create free account
hub / github.com/apache/arrow-rs / try_value

Method try_value

parquet-variant-compute/src/variant_array.rs:398–421  ·  view source on GitHub ↗

Return the [`Variant`] instance stored at the given row Note: This method does not check for nulls and the value is arbitrary (but still well-defined) if [`is_null`](Self::is_null) returns true for the index. # Panics Panics if the index is out of bounds the array value is null # Errors Errors if - the data in `typed_value` cannot be interpreted as a valid `Variant` If this is a shredded var

(&self, index: usize)

Source from the content-addressed store, hash-verified

396 /// Note: Does not do deep validation of the [`Variant`], so it is up to the
397 /// caller to ensure that the metadata and value were constructed correctly.
398 pub fn try_value(&self, index: usize) -> Result<Variant<'_, '_>> {
399 match (self.typed_value_field(), self.value_field()) {
400 // Always prefer typed_value, if available
401 (Some(typed_value), value) if typed_value.is_valid(index) => {
402 typed_value_to_variant(typed_value, value, index)
403 }
404 // Otherwise fall back to value, if available
405 (_, Some(value)) if value.is_valid(index) => variant_from_arrays_at(
406 &self.metadata,
407 value,
408 index,
409 )
410 .ok_or_else(|| {
411 ArrowError::InvalidArgumentError(format!(
412 "metadata and value fields must be binary-like arrays, instead got {} and {}",
413 self.metadata.data_type(),
414 value.data_type()
415 ))
416 }),
417 // It is technically invalid for neither value nor typed_value fields to be available,
418 // but the spec specifically requires readers to return Variant::Null in this case.
419 _ => Ok(Variant::Null),
420 }
421 }
422
423 /// Return a reference to the metadata field of the [`StructArray`]
424 pub fn metadata_field(&self) -> &ArrayRef {

Callers 2

shredded_get_pathFunction · 0.80
valueMethod · 0.80

Calls 5

typed_value_to_variantFunction · 0.85
variant_from_arrays_atFunction · 0.85
typed_value_fieldMethod · 0.80
value_fieldMethod · 0.80
is_validMethod · 0.45

Tested by

no test coverage detected