You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "fengys1996 (via GitHub)" <gi...@apache.org> on 2026/06/04 08:44:54 UTC
[I] Incorrect timestamp comparison with mixed time units [datafusion]
fengys1996 opened a new issue, #22756:
URL: https://github.com/apache/datafusion/issues/22756
### Describe the bug
When comparing two Timestamp values with different TimeUnits, DataFusion coerces both sides to the coarser time unit. This may result in a loss of precision and lead to incorrect comparison semantics.
And other timestamp operations, such as arithmetic operations and type-unification contexts like `UNION`, also choose the coarser time unit.
### To Reproduce
1. compare ts with different time unit.
```sql
SELECT
CAST(TIMESTAMP '2024-01-01 00:00:00' AS TIMESTAMP(0)) =
CAST(TIMESTAMP '2024-01-01 00:00:00.123' AS TIMESTAMP(3)) AS eq;
```
Expected:
```text
+---------------------------------------------------------------+
| Utf8("2024-01-01 00:00:00") = Utf8("2024-01-01 00:00:00.123") |
+---------------------------------------------------------------+
| false |
+---------------------------------------------------------------+
```
Actual:
```text
+---------------------------------------------------------------+
| Utf8("2024-01-01 00:00:00") = Utf8("2024-01-01 00:00:00.123") |
+---------------------------------------------------------------+
| true |
+---------------------------------------------------------------+
```
2. ts subtraction
```sql
SELECT
CAST(TIMESTAMP '2024-01-01 00:00:00.123' AS TIMESTAMP(3)) -
CAST(TIMESTAMP '2024-01-01 00:00:00' AS TIMESTAMP(0)) AS diff;
```
Expected:
```text
+----------+
| diff |
+----------+
| PT0.123S |
+----------+
```
Actual:
```text
+------+
| diff |
+------+
| P0D |
+------+
```
3. ts union
```sql
SELECT CAST(TIMESTAMP '2024-01-01 00:00:00' AS TIMESTAMP(0))
UNION ALL
SELECT CAST(TIMESTAMP '2024-01-01 00:00:00.123' AS TIMESTAMP(3));
```
Expected:
```text
+-----------------------------+
| Utf8("2024-01-01 00:00:00") |
+-----------------------------+
| 2024-01-01T00:00:00.123 |
| 2024-01-01T00:00:00 |
+-----------------------------+
```
Actual:
```text
+-----------------------------+
| Utf8("2024-01-01 00:00:00") |
+-----------------------------+
| 2024-01-01T00:00:00 |
| 2024-01-01T00:00:00 |
+-----------------------------+
```
### Expected behavior
_No response_
### Additional context
I also ran a few similar queries in ClickHouse. It appears that ClickHouse
prefers the finer precision.
--
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: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Incorrect timestamp comparison with mixed time units [datafusion]
Posted by "fengys1996 (via GitHub)" <gi...@apache.org>.
fengys1996 commented on issue #22756:
URL: https://github.com/apache/datafusion/issues/22756#issuecomment-4622257742
> take
I've already submitted a PR for this issue. Feel free to take a look if that helps.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Incorrect timestamp comparison with mixed time units [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan closed issue #22756: Incorrect timestamp comparison with mixed time units
URL: https://github.com/apache/datafusion/issues/22756
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Incorrect timestamp comparison with mixed time units [datafusion]
Posted by "mkleen (via GitHub)" <gi...@apache.org>.
mkleen commented on issue #22756:
URL: https://github.com/apache/datafusion/issues/22756#issuecomment-4622025195
take
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org