neilconway opened a new issue, #25941:
URL: https://github.com/apache/datafusion/issues/25941
### Describe the bug
A filter that casts a timestamp without a time zone to one with a time zone,
then compares it to a timestamp literal, returns the wrong rows. Both sides of
the comparison display the same value. The same comparison against a column
instead of a literal gives the right answer.
### To Reproduce
```sql
CREATE TABLE t AS VALUES (TIMESTAMP '2024-01-01 10:00:00');
CREATE TABLE l AS SELECT arrow_cast('2024-01-01T10:00:00+05:00',
'Timestamp(Nanosecond, Some("+05:00"))') AS v;
-- Both sides are 2024-01-01T10:00:00+05:00
SELECT arrow_cast(column1, 'Timestamp(Nanosecond, Some("+05:00"))') AS lhs,
v AS rhs FROM t, l;
-- Compare against a column: 1 row (correct)
SELECT count(*) FROM t, l
WHERE arrow_cast(t.column1, 'Timestamp(Nanosecond, Some("+05:00"))') = l.v;
-- Compare against the same value as a literal: 0 rows (wrong)
SELECT count(*) FROM t
WHERE arrow_cast(column1, 'Timestamp(Nanosecond, Some("+05:00"))')
= arrow_cast('2024-01-01T10:00:00+05:00', 'Timestamp(Nanosecond,
Some("+05:00"))');
```
It also happens with the more common `::timestamptz` form when a session
time zone is set:
```sql
SET datafusion.execution.time_zone = '+05:00';
CREATE TABLE t AS VALUES (TIMESTAMP '2024-01-01 10:00:00');
SELECT column1::timestamptz FROM t; -- 2024-01-01T10:00:00+05:00
SELECT count(*) FROM t WHERE column1::timestamptz = TIMESTAMPTZ '2024-01-01
10:00:00+05:00'; -- 0
```
### Expected behavior
Both literal comparisons should return 1, matching the column comparison.
### Additional context
Reproduced on `main` at commit 242b96c23. With a `+00:00` or `UTC` time zone
the results are correct. With `+05:00` or `-03:00`, the literal comparison
returns 0 rows.
*This bug report was generated by Claude.*
--
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]