This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new c43d9b347a Add test case for invalid tz in timestamp literal (#9429)
c43d9b347a is described below
commit c43d9b347ab17f458150ffbc1339b4e63d9e8b43
Author: Mohamed Abdeen <[email protected]>
AuthorDate: Sun Mar 3 10:23:21 2024 +0200
Add test case for invalid tz in timestamp literal (#9429)
* Add test case for invalid tz in timestamp literal
* add a separate unit test
---------
Co-authored-by: Mohamed Abdeen <[email protected]>
---
datafusion/functions/src/datetime/to_timestamp.rs | 25 +++++++++++++++++++++++
datafusion/sqllogictest/test_files/timestamps.slt | 4 ++++
2 files changed, 29 insertions(+)
diff --git a/datafusion/functions/src/datetime/to_timestamp.rs
b/datafusion/functions/src/datetime/to_timestamp.rs
index adba84af72..cd8593337c 100644
--- a/datafusion/functions/src/datetime/to_timestamp.rs
+++ b/datafusion/functions/src/datetime/to_timestamp.rs
@@ -561,6 +561,31 @@ mod tests {
Ok(())
}
+ #[test]
+ fn to_timestamp_with_invalid_tz() -> Result<()> {
+ let mut date_string_builder = StringBuilder::with_capacity(2, 1024);
+
+ date_string_builder.append_null();
+
+ date_string_builder.append_value("2020-09-08T13:42:29ZZ");
+
+ let string_array =
+ ColumnarValue::Array(Arc::new(date_string_builder.finish()) as
ArrayRef);
+
+ let expected_err =
+ "Arrow error: Parser error: Invalid timezone \"ZZ\": 'ZZ' is not a
valid timezone";
+ match to_timestamp(&[string_array]) {
+ Ok(_) => panic!("Expected error but got success"),
+ Err(e) => {
+ assert!(
+ e.to_string().contains(expected_err),
+ "Can not find expected error '{expected_err}'. Actual
error '{e}'"
+ );
+ }
+ }
+ Ok(())
+ }
+
#[test]
fn to_timestamp_with_no_matching_formats() -> Result<()> {
let mut date_string_builder = StringBuilder::with_capacity(2, 1024);
diff --git a/datafusion/sqllogictest/test_files/timestamps.slt
b/datafusion/sqllogictest/test_files/timestamps.slt
index d708563177..f0483aec89 100644
--- a/datafusion/sqllogictest/test_files/timestamps.slt
+++ b/datafusion/sqllogictest/test_files/timestamps.slt
@@ -465,6 +465,10 @@ SELECT TIME 'not a time' as time;
query error Cannot cast string '24:01:02' to value of Time64\(Nanosecond\) type
SELECT TIME '24:01:02' as time;
+# invalid timezone
+query error Arrow error: Parser error: Invalid timezone "ZZ": 'ZZ' is not a
valid timezone
+SELECT TIMESTAMP '2023-12-05T21:58:10.45ZZ';
+
statement ok
set datafusion.optimizer.skip_failed_rules = true