|
17 | 17 |
|
18 | 18 | //! [`VariantArray`] implementation |
19 | 19 |
|
20 | | -use crate::type_conversion::primitive_conversion_single_value; |
| 20 | +use crate::type_conversion::{generic_conversion_single_value, primitive_conversion_single_value}; |
21 | 21 | use arrow::array::{Array, ArrayRef, AsArray, BinaryViewArray, StructArray}; |
22 | 22 | use arrow::buffer::NullBuffer; |
23 | 23 | use arrow::compute::cast; |
24 | 24 | use arrow::datatypes::{ |
25 | 25 | Date32Type, Float16Type, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, |
| 26 | + TimestampMicrosecondType, TimestampNanosecondType, |
26 | 27 | }; |
27 | 28 | use arrow_schema::extension::ExtensionType; |
28 | 29 | use arrow_schema::{ArrowError, DataType, Field, FieldRef, Fields, TimeUnit}; |
| 30 | +use chrono::DateTime; |
29 | 31 | use parquet_variant::Uuid; |
30 | 32 | use parquet_variant::Variant; |
31 | 33 |
|
@@ -837,6 +839,42 @@ fn typed_value_to_variant<'a>( |
837 | 839 | DataType::Float64 => { |
838 | 840 | primitive_conversion_single_value!(Float64Type, typed_value, index) |
839 | 841 | } |
| 842 | + DataType::Timestamp(TimeUnit::Microsecond, Some(_)) => { |
| 843 | + generic_conversion_single_value!( |
| 844 | + TimestampMicrosecondType, |
| 845 | + as_primitive, |
| 846 | + |v| DateTime::from_timestamp_micros(v).unwrap(), |
| 847 | + typed_value, |
| 848 | + index |
| 849 | + ) |
| 850 | + } |
| 851 | + DataType::Timestamp(TimeUnit::Microsecond, None) => { |
| 852 | + generic_conversion_single_value!( |
| 853 | + TimestampMicrosecondType, |
| 854 | + as_primitive, |
| 855 | + |v| DateTime::from_timestamp_micros(v).unwrap().naive_utc(), |
| 856 | + typed_value, |
| 857 | + index |
| 858 | + ) |
| 859 | + } |
| 860 | + DataType::Timestamp(TimeUnit::Nanosecond, Some(_)) => { |
| 861 | + generic_conversion_single_value!( |
| 862 | + TimestampNanosecondType, |
| 863 | + as_primitive, |
| 864 | + DateTime::from_timestamp_nanos, |
| 865 | + typed_value, |
| 866 | + index |
| 867 | + ) |
| 868 | + } |
| 869 | + DataType::Timestamp(TimeUnit::Nanosecond, None) => { |
| 870 | + generic_conversion_single_value!( |
| 871 | + TimestampNanosecondType, |
| 872 | + as_primitive, |
| 873 | + |v| DateTime::from_timestamp_nanos(v).naive_utc(), |
| 874 | + typed_value, |
| 875 | + index |
| 876 | + ) |
| 877 | + } |
840 | 878 | // todo other types here (note this is very similar to cast_to_variant.rs) |
841 | 879 | // so it would be great to figure out how to share this code |
842 | 880 | _ => { |
|
0 commit comments