Function cast_to_variant

Source
pub fn cast_to_variant(input: &dyn Array) -> Result<VariantArray, ArrowError>
Expand description

Casts a typed arrow [Array] to a VariantArray. This is useful when you need to convert a specific data type

§Arguments

  • input - A reference to the input [Array] to cast

§Notes

If the input array element is null, the corresponding element in the output VariantArray will also be null (not Variant::Null).

§Example

// input is an Int64Array, which will be cast to a VariantArray
let input = Int64Array::from(vec![Some(1), None, Some(3)]);
let result = cast_to_variant(&input).unwrap();
assert_eq!(result.len(), 3);
assert_eq!(result.value(0), Variant::Int64(1));
assert!(result.is_null(1)); // note null, not Variant::Null
assert_eq!(result.value(2), Variant::Int64(3));