Skip to content

Commit

Permalink
Unit test cases for apache#3744 (CSV reader infers Date64 type for fi…
Browse files Browse the repository at this point in the history
…elds like "2020-03-19 00:00:00" that it can't parse to Date64)
  • Loading branch information
sacundim committed Feb 22, 2023
1 parent 61ea9f2 commit e29fe22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion arrow-cast/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4887,7 +4887,17 @@ mod tests {
Some("Not a valid date"),
None,
])) as ArrayRef;
for array in &[a1, a2] {
let a3 = Arc::new(StringArray::from(vec![
Some("2020-09-08 12:00:00"),
Some("Not a valid date"),
None,
])) as ArrayRef;
let a4 = Arc::new(LargeStringArray::from(vec![
Some("2020-09-08 12:00:00"),
Some("Not a valid date"),
None,
])) as ArrayRef;
for array in &[a1, a2, a3, a4] {
let to_type = DataType::Date64;
let b = cast(array, &to_type).unwrap();
let c = b.as_any().downcast_ref::<Date64Array>().unwrap();
Expand Down
13 changes: 13 additions & 0 deletions arrow-csv/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,19 @@ mod tests {
);
}

#[test]
fn test_can_parse_inferred_date64() {
let raw = "1900-02-28 12:34:56";
assert_eq!(
infer_field_schema(raw, None),
DataType::Date64
);
assert_eq!(
parse_item::<Date64Type>(raw),
Some(-2203932304000)
);
}

#[test]
fn test_parse_decimal() {
let tests = [
Expand Down

0 comments on commit e29fe22

Please sign in to comment.