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/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 4a0c7f35a0 Consider timezones with `UTC` and `+00:00` to be the same
(#10960)
4a0c7f35a0 is described below
commit 4a0c7f35a02ef71fcea518a3566edc9b56866cae
Author: Marvin Lanhenke <[email protected]>
AuthorDate: Fri Jun 21 18:18:14 2024 +0200
Consider timezones with `UTC` and `+00:00` to be the same (#10960)
* feat: add temporal_coercion check
* fix: add return stmt
* chore: add slts
* fix: remove println
* Update datafusion/expr/src/type_coercion/binary.rs
---------
Co-authored-by: Andrew Lamb <[email protected]>
---
datafusion/expr/src/type_coercion/binary.rs | 14 +++++++++-----
datafusion/sqllogictest/test_files/timestamps.slt | 23 +++++++++++++++++++++++
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/datafusion/expr/src/type_coercion/binary.rs
b/datafusion/expr/src/type_coercion/binary.rs
index 615bb3ac56..ea9d0c2fe7 100644
--- a/datafusion/expr/src/type_coercion/binary.rs
+++ b/datafusion/expr/src/type_coercion/binary.rs
@@ -1050,12 +1050,16 @@ fn temporal_coercion(lhs_type: &DataType, rhs_type:
&DataType) -> Option<DataTyp
}
(Timestamp(lhs_unit, lhs_tz), Timestamp(rhs_unit, rhs_tz)) => {
let tz = match (lhs_tz, rhs_tz) {
- // can't cast across timezones
(Some(lhs_tz), Some(rhs_tz)) => {
- if lhs_tz != rhs_tz {
- return None;
- } else {
- Some(lhs_tz.clone())
+ match (lhs_tz.as_ref(), rhs_tz.as_ref()) {
+ // UTC and "+00:00" are the same by definition. Most
other timezones
+ // do not have a 1-1 mapping between timezone and an
offset from UTC
+ ("UTC", "+00:00") | ("+00:00", "UTC") =>
Some(lhs_tz.clone()),
+ (lhs, rhs) if lhs == rhs => Some(lhs_tz.clone()),
+ // can't cast across timezones
+ _ => {
+ return None;
+ }
}
}
(Some(lhs_tz), None) => Some(lhs_tz.clone()),
diff --git a/datafusion/sqllogictest/test_files/timestamps.slt
b/datafusion/sqllogictest/test_files/timestamps.slt
index 7d5d601bbf..96d846d449 100644
--- a/datafusion/sqllogictest/test_files/timestamps.slt
+++ b/datafusion/sqllogictest/test_files/timestamps.slt
@@ -2801,3 +2801,26 @@ query B
select current_time = current_time;
----
true
+
+# Test temporal coercion for UTC
+query ?
+select arrow_cast('2024-06-17T11:00:00', 'Timestamp(Nanosecond, Some("UTC"))')
- arrow_cast('2024-06-17T12:00:00', 'Timestamp(Microsecond, Some("UTC"))');
+----
+0 days -1 hours 0 mins 0.000000 secs
+
+query ?
+select arrow_cast('2024-06-17T13:00:00', 'Timestamp(Nanosecond,
Some("+00:00"))') - arrow_cast('2024-06-17T12:00:00', 'Timestamp(Microsecond,
Some("UTC"))');
+----
+0 days 1 hours 0 mins 0.000000 secs
+
+query ?
+select arrow_cast('2024-06-17T13:00:00', 'Timestamp(Nanosecond, Some("UTC"))')
- arrow_cast('2024-06-17T12:00:00', 'Timestamp(Microsecond, Some("+00:00"))');
+----
+0 days 1 hours 0 mins 0.000000 secs
+
+# not supported: coercion across timezones
+query error
+select arrow_cast('2024-06-17T13:00:00', 'Timestamp(Nanosecond, Some("UTC"))')
- arrow_cast('2024-06-17T12:00:00', 'Timestamp(Microsecond, Some("+01:00"))');
+
+query error
+select arrow_cast('2024-06-17T13:00:00', 'Timestamp(Nanosecond,
Some("+00:00"))') - arrow_cast('2024-06-17T12:00:00', 'Timestamp(Microsecond,
Some("+01:00"))');
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]