From 98c298ce09d806266d8e01407e38ff998f729065 Mon Sep 17 00:00:00 2001 From: vidyasankarv Date: Wed, 15 May 2024 14:23:37 +0530 Subject: [PATCH] add test for string array cast to date --- .../execution/datafusion/expressions/cast.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/execution/datafusion/expressions/cast.rs b/core/src/execution/datafusion/expressions/cast.rs index 6bcab1cdae..b643e9ea50 100644 --- a/core/src/execution/datafusion/expressions/cast.rs +++ b/core/src/execution/datafusion/expressions/cast.rs @@ -1762,9 +1762,8 @@ mod tests { .for_each(|v| assert_eq!(v.unwrap(), 18262)); } + #[test] fn test_cast_string_to_invalid_dates() { - // basic - let array_with_invalid_date: ArrayRef = Arc::new(StringArray::from(vec![ Some("2020"), Some("2020-01"), @@ -1772,6 +1771,22 @@ mod tests { Some("2020-010-01T"), Some("2020-01-01T"), ])); + + for eval_mode in &[EvalMode::Legacy, EvalMode::Try] { + let result = + Cast::cast_string_to_date(&array_with_invalid_date, &DataType::Date32, *eval_mode) + .unwrap(); + + let date32_array = result + .as_any() + .downcast_ref::() + .unwrap(); + assert_eq!( + date32_array.iter().collect::>(), + vec![Some(18262), Some(18262), Some(18262), None, Some(18262)] + ); + } + let result = Cast::cast_string_to_date(&array_with_invalid_date, &DataType::Date32, EvalMode::Ansi); match result {