Skip to content

Commit

Permalink
Add test case for invalid tz in timestamp literal (apache#9429)
Browse files Browse the repository at this point in the history
* Add test case for invalid tz in timestamp literal

* add a separate unit test

---------

Co-authored-by: Mohamed Abdeen <mohamed.abdeen@paytabs.com>
  • Loading branch information
MohamedAbdeen21 and Mohamed Abdeen authored Mar 3, 2024
1 parent 4ea536b commit c43d9b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions datafusion/functions/src/datetime/to_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions datafusion/sqllogictest/test_files/timestamps.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c43d9b3

Please sign in to comment.