Downcast Arrow columns once, returning typed references paired with their DataType.
(
batch: &'a RecordBatch,
field_indices: &[usize],
fields: &'a [crate::spec::DataField],
)
| 836 | |
| 837 | /// Downcast Arrow columns once, returning typed references paired with their DataType. |
| 838 | fn downcast_columns<'a>( |
| 839 | batch: &'a RecordBatch, |
| 840 | field_indices: &[usize], |
| 841 | fields: &'a [crate::spec::DataField], |
| 842 | ) -> crate::Result<Vec<(TypedColumn<'a>, &'a crate::spec::DataField)>> { |
| 843 | use arrow_array::Array; |
| 844 | field_indices |
| 845 | .iter() |
| 846 | .map(|&col_idx| { |
| 847 | let field = &fields[col_idx]; |
| 848 | let col = batch.column(col_idx); |
| 849 | let typed = |
| 850 | match field.data_type() { |
| 851 | DataType::Boolean(_) => TypedColumn::Boolean( |
| 852 | col.as_any() |
| 853 | .downcast_ref() |
| 854 | .ok_or_else(|| type_mismatch_err("Boolean", col_idx))?, |
| 855 | ), |
| 856 | DataType::TinyInt(_) => TypedColumn::Int8( |
| 857 | col.as_any() |
| 858 | .downcast_ref() |
| 859 | .ok_or_else(|| type_mismatch_err("TinyInt", col_idx))?, |
| 860 | ), |
| 861 | DataType::SmallInt(_) => TypedColumn::Int16( |
| 862 | col.as_any() |
| 863 | .downcast_ref() |
| 864 | .ok_or_else(|| type_mismatch_err("SmallInt", col_idx))?, |
| 865 | ), |
| 866 | DataType::Int(_) => TypedColumn::Int32( |
| 867 | col.as_any() |
| 868 | .downcast_ref() |
| 869 | .ok_or_else(|| type_mismatch_err("Int", col_idx))?, |
| 870 | ), |
| 871 | DataType::BigInt(_) => TypedColumn::Int64( |
| 872 | col.as_any() |
| 873 | .downcast_ref() |
| 874 | .ok_or_else(|| type_mismatch_err("BigInt", col_idx))?, |
| 875 | ), |
| 876 | DataType::Float(_) => TypedColumn::Float32( |
| 877 | col.as_any() |
| 878 | .downcast_ref() |
| 879 | .ok_or_else(|| type_mismatch_err("Float", col_idx))?, |
| 880 | ), |
| 881 | DataType::Double(_) => TypedColumn::Float64( |
| 882 | col.as_any() |
| 883 | .downcast_ref() |
| 884 | .ok_or_else(|| type_mismatch_err("Double", col_idx))?, |
| 885 | ), |
| 886 | DataType::Char(_) | DataType::VarChar(_) => { |
| 887 | if let Some(arr) = col.as_any().downcast_ref::<arrow_array::StringArray>() { |
| 888 | TypedColumn::Utf8(arr) |
| 889 | } else if let Some(arr) = |
| 890 | col.as_any().downcast_ref::<arrow_array::StringViewArray>() |
| 891 | { |
| 892 | TypedColumn::Utf8View(arr) |
| 893 | } else if let Some(arr) = |
| 894 | col.as_any().downcast_ref::<arrow_array::LargeStringArray>() |
| 895 | { |
no test coverage detected