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 14a8681c0a feat(7849): coerce TIMESTAMP to TIMESTAMPTZ (#7850)
14a8681c0a is described below
commit 14a8681c0a5cde4f2b77861010b72ed337829681
Author: Martin Hilton <[email protected]>
AuthorDate: Wed Oct 18 22:20:34 2023 +0100
feat(7849): coerce TIMESTAMP to TIMESTAMPTZ (#7850)
* feat(7849): coerce TIMESTAMP to TIMESTAMPTZ
Add coercion rules to support coercion from timestamp types without
a timezone to a timestamp with a timezone. Like with the coercion
of strings or numeric constants, when a function requires the
TIMEZONE_WILDCARD placeholder timezone "+00" will be used as the
timezone offset.
* review comments
Add additional SQL logic test suggested in review.
* more review suggestions
Add a positive test case for TIMESTAMPTZ and TIMESTAMP comparison.
---
datafusion/expr/src/type_coercion/functions.rs | 4 ++--
datafusion/sqllogictest/test_files/timestamps.slt | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/datafusion/expr/src/type_coercion/functions.rs
b/datafusion/expr/src/type_coercion/functions.rs
index 17ca40236d..b387667ad1 100644
--- a/datafusion/expr/src/type_coercion/functions.rs
+++ b/datafusion/expr/src/type_coercion/functions.rs
@@ -228,7 +228,7 @@ fn coerced_from<'a>(
Timestamp(_, Some(from_tz)) => {
Some(Timestamp(unit.clone(), Some(from_tz.clone())))
}
- Null | Date32 | Utf8 | LargeUtf8 => {
+ Null | Date32 | Utf8 | LargeUtf8 | Timestamp(_, None) => {
// In the absence of any other information assume the time
zone is "+00" (UTC).
Some(Timestamp(unit.clone(), Some("+00".into())))
}
@@ -238,7 +238,7 @@ fn coerced_from<'a>(
Timestamp(_, Some(_))
if matches!(
type_from,
- Null | Timestamp(_, Some(_)) | Date32 | Utf8 | LargeUtf8
+ Null | Timestamp(_, _) | Date32 | Utf8 | LargeUtf8
) =>
{
Some(type_into.clone())
diff --git a/datafusion/sqllogictest/test_files/timestamps.slt
b/datafusion/sqllogictest/test_files/timestamps.slt
index edafe18caa..fea61b076e 100644
--- a/datafusion/sqllogictest/test_files/timestamps.slt
+++ b/datafusion/sqllogictest/test_files/timestamps.slt
@@ -1389,6 +1389,12 @@ SELECT date_bin('1 day', TIMESTAMPTZ '2022-01-01
20:10:00Z', TIMESTAMPTZ '2020-0
----
2022-01-02T00:00:00+07:00
+# coerce TIMESTAMP to TIMESTAMPTZ
+query P
+SELECT date_bin('1 day', TIMESTAMPTZ '2022-01-01 20:10:00Z', TIMESTAMP
'2020-01-01')
+----
+2022-01-01T07:00:00+07:00
+
# postgresql: 1
query R
SELECT date_part('hour', TIMESTAMPTZ '2000-01-01T01:01:01') as part
@@ -1758,3 +1764,15 @@ query T
SELECT arrow_typeof(date_bin(INTERVAL '1 day', time,
'1970-01-01T00:00:00+05:00')) FROM foo LIMIT 1
----
Timestamp(Nanosecond, Some("+05:00"))
+
+
+# timestamp comparison with and without timezone
+query B
+SELECT TIMESTAMPTZ '2022-01-01 20:10:00Z' = TIMESTAMP '2020-01-01'
+----
+false
+
+query B
+SELECT TIMESTAMPTZ '2020-01-01 00:00:00Z' = TIMESTAMP '2020-01-01'
+----
+true