Skip to content

Commit

Permalink
add test for string array cast to date
Browse files Browse the repository at this point in the history
  • Loading branch information
vidyasankarv committed May 15, 2024
1 parent cdf8888 commit 98c298c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/src/execution/datafusion/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,16 +1762,31 @@ 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"),
Some("2020-01-01"),
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::<arrow::array::Date32Array>()
.unwrap();
assert_eq!(
date32_array.iter().collect::<Vec<_>>(),
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 {
Expand Down

0 comments on commit 98c298c

Please sign in to comment.