From a478522001cc6aa32e063ef9e4223f23c8fc60cd Mon Sep 17 00:00:00 2001 From: Wei-Ting Kuo Date: Tue, 16 Aug 2022 04:39:35 +0800 Subject: [PATCH 1/2] add test case for cast_timestamp_before_1970 --- datafusion/core/tests/sql/timestamp.rs | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 4ae81bfc62c6..1800553fb190 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -1433,3 +1433,37 @@ 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(()) +} From 98a67c57f39d9ff7b73d9e9642a0acac98353a1d Mon Sep 17 00:00:00 2001 From: Wei-Ting Kuo Date: Tue, 16 Aug 2022 04:42:29 +0800 Subject: [PATCH 2/2] datafusion/core/tests/sql/timestamp.rs --- datafusion/core/tests/sql/timestamp.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 1800553fb190..9f9004d6bc6e 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -1434,7 +1434,6 @@ async fn timestamp_array_add_interval() -> Result<()> { Ok(()) } - #[tokio::test] async fn cast_timestamp_before_1970() -> Result<()> { // this is a repro for issue #3082 @@ -1464,6 +1463,5 @@ async fn cast_timestamp_before_1970() -> Result<()> { assert_batches_eq!(expected, &actual); - Ok(()) }