From 524ea7fd4912ded45f1ab69e8c33520f5698394a Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Sat, 21 Aug 2021 14:13:33 +0200 Subject: [PATCH] add cast date32 -> i64; date64 -> i32 --- src/compute/cast/mod.rs | 4 ++++ tests/it/compute/cast.rs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/compute/cast/mod.rs b/src/compute/cast/mod.rs index eca849ea481..9dd5ef5f33d 100644 --- a/src/compute/cast/mod.rs +++ b/src/compute/cast/mod.rs @@ -239,9 +239,11 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { (Int32, Date32) => true, (Int32, Time32(_)) => true, (Date32, Int32) => true, + (Date32, Int64) => true, (Time32(_), Int32) => true, (Int64, Date64) => true, (Int64, Time64(_)) => true, + (Date64, Int32) => true, (Date64, Int64) => true, (Time64(_), Int64) => true, (Date32, Date64) => true, @@ -674,6 +676,7 @@ fn cast_with_options( } // No support for microsecond/nanosecond with i32 (Date32, Int32) => primitive_to_same_primitive_dyn::(array, to_type), + (Date32, Int64) => primitive_to_primitive_dyn::(array, to_type, options), (Time32(_), Int32) => primitive_to_same_primitive_dyn::(array, to_type), (Int64, Date64) => primitive_to_same_primitive_dyn::(array, to_type), // No support for second/milliseconds with i64 @@ -684,6 +687,7 @@ fn cast_with_options( primitive_to_same_primitive_dyn::(array, to_type) } + (Date64, Int32) => primitive_to_primitive_dyn::(array, to_type, options), (Date64, Int64) => primitive_to_same_primitive_dyn::(array, to_type), (Time64(_), Int64) => primitive_to_same_primitive_dyn::(array, to_type), (Date32, Date64) => primitive_dyn!(array, date32_to_date64), diff --git a/tests/it/compute/cast.rs b/tests/it/compute/cast.rs index 8abb8afc29e..36ebfde4f90 100644 --- a/tests/it/compute/cast.rs +++ b/tests/it/compute/cast.rs @@ -378,6 +378,26 @@ fn date32_to_int32() { ); } +#[test] +fn date64_to_int32() { + test_primitive_to_primitive( + &[10000i64, 17890], + DataType::Date64, + &[10000i32, 17890], + DataType::Int32, + ); +} + +#[test] +fn date32_to_int64() { + test_primitive_to_primitive( + &[10000i32, 17890], + DataType::Date32, + &[10000i64, 17890], + DataType::Int64, + ); +} + #[test] fn int32_to_date32() { test_primitive_to_primitive(