use crate::{downcast_value, DataFusionError, Result};
use arrow::{
array::{
Array, BinaryArray, BooleanArray, Date32Array, Date64Array, Decimal128Array,
Decimal256Array, DictionaryArray, FixedSizeBinaryArray, FixedSizeListArray,
Float32Array, Float64Array, GenericBinaryArray, GenericListArray,
GenericStringArray, Int32Array, Int64Array, IntervalDayTimeArray,
IntervalMonthDayNanoArray, IntervalYearMonthArray, LargeListArray, ListArray,
MapArray, NullArray, OffsetSizeTrait, PrimitiveArray, StringArray, StructArray,
Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
TimestampNanosecondArray, TimestampSecondArray, UInt32Array, UInt64Array,
UInt8Array, UnionArray,
},
datatypes::{ArrowDictionaryKeyType, ArrowPrimitiveType},
};
use arrow_array::{BinaryViewArray, StringViewArray};
pub fn as_date32_array(array: &dyn Array) -> Result<&Date32Array> {
Ok(downcast_value!(array, Date32Array))
}
pub fn as_struct_array(array: &dyn Array) -> Result<&StructArray> {
Ok(downcast_value!(array, StructArray))
}
pub fn as_uint8_array(array: &dyn Array) -> Result<&UInt8Array> {
Ok(downcast_value!(array, UInt8Array))
}
pub fn as_int32_array(array: &dyn Array) -> Result<&Int32Array> {
Ok(downcast_value!(array, Int32Array))
}
pub fn as_int64_array(array: &dyn Array) -> Result<&Int64Array> {
Ok(downcast_value!(array, Int64Array))
}
pub fn as_decimal128_array(array: &dyn Array) -> Result<&Decimal128Array> {
Ok(downcast_value!(array, Decimal128Array))
}
pub fn as_decimal256_array(array: &dyn Array) -> Result<&Decimal256Array> {
Ok(downcast_value!(array, Decimal256Array))
}
pub fn as_float32_array(array: &dyn Array) -> Result<&Float32Array> {
Ok(downcast_value!(array, Float32Array))
}
pub fn as_float64_array(array: &dyn Array) -> Result<&Float64Array> {
Ok(downcast_value!(array, Float64Array))
}
pub fn as_string_array(array: &dyn Array) -> Result<&StringArray> {
Ok(downcast_value!(array, StringArray))
}
pub fn as_string_view_array(array: &dyn Array) -> Result<&StringViewArray> {
Ok(downcast_value!(array, StringViewArray))
}
pub fn as_uint32_array(array: &dyn Array) -> Result<&UInt32Array> {
Ok(downcast_value!(array, UInt32Array))
}
pub fn as_uint64_array(array: &dyn Array) -> Result<&UInt64Array> {
Ok(downcast_value!(array, UInt64Array))
}
pub fn as_boolean_array(array: &dyn Array) -> Result<&BooleanArray> {
Ok(downcast_value!(array, BooleanArray))
}
pub fn as_list_array(array: &dyn Array) -> Result<&ListArray> {
Ok(downcast_value!(array, ListArray))
}
pub fn as_dictionary_array<T: ArrowDictionaryKeyType>(
array: &dyn Array,
) -> Result<&DictionaryArray<T>> {
Ok(downcast_value!(array, DictionaryArray, T))
}
pub fn as_generic_binary_array<T: OffsetSizeTrait>(
array: &dyn Array,
) -> Result<&GenericBinaryArray<T>> {
Ok(downcast_value!(array, GenericBinaryArray, T))
}
pub fn as_generic_list_array<T: OffsetSizeTrait>(
array: &dyn Array,
) -> Result<&GenericListArray<T>> {
Ok(downcast_value!(array, GenericListArray, T))
}
pub fn as_large_list_array(array: &dyn Array) -> Result<&LargeListArray> {
Ok(downcast_value!(array, LargeListArray))
}
pub fn as_primitive_array<T: ArrowPrimitiveType>(
array: &dyn Array,
) -> Result<&PrimitiveArray<T>> {
Ok(downcast_value!(array, PrimitiveArray, T))
}
pub fn as_map_array(array: &dyn Array) -> Result<&MapArray> {
Ok(downcast_value!(array, MapArray))
}
pub fn as_null_array(array: &dyn Array) -> Result<&NullArray> {
Ok(downcast_value!(array, NullArray))
}
pub fn as_union_array(array: &dyn Array) -> Result<&UnionArray> {
Ok(downcast_value!(array, UnionArray))
}
pub fn as_time32_second_array(array: &dyn Array) -> Result<&Time32SecondArray> {
Ok(downcast_value!(array, Time32SecondArray))
}
pub fn as_time32_millisecond_array(array: &dyn Array) -> Result<&Time32MillisecondArray> {
Ok(downcast_value!(array, Time32MillisecondArray))
}
pub fn as_time64_microsecond_array(array: &dyn Array) -> Result<&Time64MicrosecondArray> {
Ok(downcast_value!(array, Time64MicrosecondArray))
}
pub fn as_time64_nanosecond_array(array: &dyn Array) -> Result<&Time64NanosecondArray> {
Ok(downcast_value!(array, Time64NanosecondArray))
}
pub fn as_timestamp_nanosecond_array(
array: &dyn Array,
) -> Result<&TimestampNanosecondArray> {
Ok(downcast_value!(array, TimestampNanosecondArray))
}
pub fn as_timestamp_millisecond_array(
array: &dyn Array,
) -> Result<&TimestampMillisecondArray> {
Ok(downcast_value!(array, TimestampMillisecondArray))
}
pub fn as_timestamp_microsecond_array(
array: &dyn Array,
) -> Result<&TimestampMicrosecondArray> {
Ok(downcast_value!(array, TimestampMicrosecondArray))
}
pub fn as_timestamp_second_array(array: &dyn Array) -> Result<&TimestampSecondArray> {
Ok(downcast_value!(array, TimestampSecondArray))
}
pub fn as_interval_ym_array(array: &dyn Array) -> Result<&IntervalYearMonthArray> {
Ok(downcast_value!(array, IntervalYearMonthArray))
}
pub fn as_interval_dt_array(array: &dyn Array) -> Result<&IntervalDayTimeArray> {
Ok(downcast_value!(array, IntervalDayTimeArray))
}
pub fn as_interval_mdn_array(array: &dyn Array) -> Result<&IntervalMonthDayNanoArray> {
Ok(downcast_value!(array, IntervalMonthDayNanoArray))
}
pub fn as_binary_array(array: &dyn Array) -> Result<&BinaryArray> {
Ok(downcast_value!(array, BinaryArray))
}
pub fn as_binary_view_array(array: &dyn Array) -> Result<&BinaryViewArray> {
Ok(downcast_value!(array, BinaryViewArray))
}
pub fn as_fixed_size_list_array(array: &dyn Array) -> Result<&FixedSizeListArray> {
Ok(downcast_value!(array, FixedSizeListArray))
}
pub fn as_fixed_size_binary_array(array: &dyn Array) -> Result<&FixedSizeBinaryArray> {
Ok(downcast_value!(array, FixedSizeBinaryArray))
}
pub fn as_date64_array(array: &dyn Array) -> Result<&Date64Array> {
Ok(downcast_value!(array, Date64Array))
}
pub fn as_generic_string_array<T: OffsetSizeTrait>(
array: &dyn Array,
) -> Result<&GenericStringArray<T>> {
Ok(downcast_value!(array, GenericStringArray, T))
}