MCPcopy Create free account
hub / github.com/apache/datafusion / try_from_array

Method try_from_array

datafusion/common/src/scalar/mod.rs:3914–4163  ·  view source on GitHub ↗

Converts a value in `array` at `index` into a ScalarValue

(array: &dyn Array, index: usize)

Source from the content-addressed store, hash-verified

3912
3913 /// Converts a value in `array` at `index` into a ScalarValue
3914 pub fn try_from_array(array: &dyn Array, index: usize) -> Result<Self> {
3915 // handle NULL value
3916 if array.is_null(index) {
3917 return array.data_type().try_into();
3918 }
3919
3920 Ok(match array.data_type() {
3921 DataType::Null => ScalarValue::Null,
3922 DataType::Decimal32(precision, scale) => {
3923 ScalarValue::get_decimal_value_from_array(
3924 array, index, *precision, *scale,
3925 )?
3926 }
3927 DataType::Decimal64(precision, scale) => {
3928 ScalarValue::get_decimal_value_from_array(
3929 array, index, *precision, *scale,
3930 )?
3931 }
3932 DataType::Decimal128(precision, scale) => {
3933 ScalarValue::get_decimal_value_from_array(
3934 array, index, *precision, *scale,
3935 )?
3936 }
3937 DataType::Decimal256(precision, scale) => {
3938 ScalarValue::get_decimal_value_from_array(
3939 array, index, *precision, *scale,
3940 )?
3941 }
3942 DataType::Boolean => typed_cast!(array, index, as_boolean_array, Boolean)?,
3943 DataType::Float64 => typed_cast!(array, index, as_float64_array, Float64)?,
3944 DataType::Float32 => typed_cast!(array, index, as_float32_array, Float32)?,
3945 DataType::Float16 => typed_cast!(array, index, as_float16_array, Float16)?,
3946 DataType::UInt64 => typed_cast!(array, index, as_uint64_array, UInt64)?,
3947 DataType::UInt32 => typed_cast!(array, index, as_uint32_array, UInt32)?,
3948 DataType::UInt16 => typed_cast!(array, index, as_uint16_array, UInt16)?,
3949 DataType::UInt8 => typed_cast!(array, index, as_uint8_array, UInt8)?,
3950 DataType::Int64 => typed_cast!(array, index, as_int64_array, Int64)?,
3951 DataType::Int32 => typed_cast!(array, index, as_int32_array, Int32)?,
3952 DataType::Int16 => typed_cast!(array, index, as_int16_array, Int16)?,
3953 DataType::Int8 => typed_cast!(array, index, as_int8_array, Int8)?,
3954 DataType::Binary => typed_cast!(array, index, as_binary_array, Binary)?,
3955 DataType::LargeBinary => {
3956 typed_cast!(array, index, as_large_binary_array, LargeBinary)?
3957 }
3958 DataType::BinaryView => {
3959 typed_cast!(array, index, as_binary_view_array, BinaryView)?
3960 }
3961 DataType::Utf8 => typed_cast!(array, index, as_string_array, Utf8)?,
3962 DataType::LargeUtf8 => {
3963 typed_cast!(array, index, as_large_string_array, LargeUtf8)?
3964 }
3965 DataType::Utf8View => {
3966 typed_cast!(array, index, as_string_view_array, Utf8View)?
3967 }
3968 DataType::List(field) => {
3969 let list_array = array.as_list::<i32>();
3970 let nested_array = list_array.value(index);
3971 // Produces a single element `ListArray` with the value at `index`.

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
as_large_list_arrayFunction · 0.85
as_fixed_size_list_arrayFunction · 0.85
as_list_view_arrayFunction · 0.85
as_large_list_view_arrayFunction · 0.85
FixedSizeBinaryClass · 0.85
as_union_arrayFunction · 0.85
build_list_scalarMethod · 0.80
with_fieldMethod · 0.80

Tested by

no test coverage detected