Skip to content

Commit

Permalink
add test case for cast_timestamp_before_1970 (#3163)
Browse files Browse the repository at this point in the history
* add test case for cast_timestamp_before_1970

* datafusion/core/tests/sql/timestamp.rs
  • Loading branch information
waitingkuo committed Aug 15, 2022
1 parent 9543d38 commit e57dead
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions datafusion/core/tests/sql/timestamp.rs
Expand Up @@ -1433,3 +1433,35 @@ async fn timestamp_array_add_interval() -> Result<()> {
assert_batches_eq!(expected, &actual);
Ok(())
}

#[tokio::test]
async fn cast_timestamp_before_1970() -> Result<()> {
// this is a repro for issue #3082
let ctx = SessionContext::new();

let sql = "select cast('1969-01-01T00:00:00Z' as timestamp);";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+-------------------------------------------------------------------+",
"| CAST(Utf8(\"1969-01-01T00:00:00Z\") AS Timestamp(Nanosecond, None)) |",
"+-------------------------------------------------------------------+",
"| 1969-01-01 00:00:00 |",
"+-------------------------------------------------------------------+",
];

assert_batches_eq!(expected, &actual);

let sql = "select cast('1969-01-01T00:00:00.1Z' as timestamp);";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------------------------------------------------------------------+",
"| CAST(Utf8(\"1969-01-01T00:00:00.1Z\") AS Timestamp(Nanosecond, None)) |",
"+---------------------------------------------------------------------+",
"| 1969-01-01 00:00:00.100 |",
"+---------------------------------------------------------------------+",
];

assert_batches_eq!(expected, &actual);

Ok(())
}

0 comments on commit e57dead

Please sign in to comment.