Ruchirtripathi commented on code in PR #25099:
URL: https://github.com/apache/datafusion/pull/25099#discussion_r4103418131


##########
datafusion/sqllogictest/test_files/datetime/timestamps.slt:
##########
@@ -5529,3 +5533,75 @@ query P
 SELECT date_bin(NULL, TIMESTAMP '2023-01-01 12:30:00', TIMESTAMP '2023-01-01 
12:00:00')
 ----
 NULL
+
+# Issue 25095: Optimizer incorrectly unwrapping timestamp cast when session 
timezone is not UTC
+statement ok
+set datafusion.execution.time_zone = 'Asia/Singapore';
+
+statement ok
+create table t_25095 as select TIMESTAMP '2024-11-01T00:00:00' as ts;
+
+statement ok
+create table u_25095 as select '2024-10-31T16:00:00Z'::timestamptz as tstz;
+
+# 2024-11-01 00:00 in Singapore is 2024-10-31 16:00 UTC
+query I
+select count(*) from t_25095 where ts::timestamptz = 
'2024-10-31T16:00:00Z'::timestamptz;
+----
+1
+
+query I
+select count(*) from t_25095 where ts::timestamptz = 
'2024-11-01T00:00:00Z'::timestamptz;
+----
+0
+
+# the same rewrite occurs for an implicit coercion
+query I
+select count(*) from t_25095 where ts = '2024-10-31T16:00:00Z'::timestamptz;
+----
+1
+
+# control: a column against a column, thus the optimizer unwraps nothing
+query I
+select count(*) from t_25095, u_25095 where t_25095.ts::timestamptz = 
u_25095.tstz;
+----
+1
+
+# A timezone-aware column against a timezone-naive literal

Review Comment:
   I've updated the comment in the test file so it's no longer misleading!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to