No type coercion between time values with different units (`Time64(µs) = Time64(ns)` fails)
維護者通常 1 天內回覆
評估
這個 Issue 還沒有評估資料。
描述
Describe the bug
DataFusion has no type coercion between Arrow time types with different units (Time32(Second), Time32(Millisecond), Time64(Microsecond), Time64(Nanosecond)). Comparisons, IN lists, join keys, UNION, and coalesce that mix two of them fail during planning:
Cannot infer common argument type for comparison operation Time64(µs) = Time64(ns)
A common way to hit this is comparing a Parquet TIME(MICROS) column, which is read as Time64(µs), with a SQL TIME value, which is Time64(ns). pyarrow writes Python datetime.time values as TIME(MICROS) by default.
@kumarUjjawal found this while reviewing #27316: https://github.com/apache/datafusion/pull/27316#discussion_r4533709191
To Reproduce
Write a file with pyarrow defaults:
import datetime
import pyarrow as pa
import pyarrow.parquet as pq
pq.write_table(pa.table({"t": [datetime.time(12, 0), datetime.time(13, 30)]}), "times.parquet")
Then run:
CREATE EXTERNAL TABLE pq STORED AS PARQUET LOCATION 'times.parquet';
SELECT arrow_typeof(t) FROM pq LIMIT 1; -- Time64(µs)
SELECT t FROM pq WHERE t = '12:00:00'; -- works, the string is cast to Time64(µs)
SELECT t FROM pq WHERE t = TIME '12:00:00';
SELECT t FROM pq WHERE t < TIME '13:00:00';
SELECT t FROM pq WHERE t IN (TIME '12:00:00', TIME '13:30:00');
CREATE TABLE schedule(s TIME) AS VALUES (TIME '12:00:00');
SELECT * FROM pq JOIN schedule ON t = s;
SELECT t FROM pq UNION ALL SELECT s FROM schedule;
SELECT coalesce(t, TIME '00:00:00') FROM pq;
Every query after the string comparison fails:
| Query | Error |
|---|---|
t = TIME '12:00:00' |
Cannot infer common argument type for comparison operation Time64(µs) = Time64(ns) |
t < TIME '13:00:00' |
Cannot infer common argument type for comparison operation Time64(µs) < Time64(ns) |
t IN (...) |
Can not find compatible types to compare Time64(µs) with [Time64(ns), Time64(ns)] |
JOIN ... ON t = s |
Cannot infer common argument type for comparison operation Time64(µs) = Time64(ns) |
UNION ALL |
Incompatible inputs for Union: Previous inputs were of type Time64(µs), but got incompatible type Time64(ns) on column 's' |
coalesce |
No function matches the given name and argument types 'coalesce(Time64(µs), Time64(ns))' |
Any two different units fail the same way, for example arrow_cast('12:00:00', 'Time32(Millisecond)') = arrow_cast('12:00:00', 'Time32(Second)').
Expected behavior
Time values with different units coerce to the finer unit, as timestamps already do (CAST('2024-01-01 12:00:00' AS TIMESTAMP(0)) = CAST('2024-01-01 12:00:00' AS TIMESTAMP) returns true). All the queries above plan and return results.
Additional context
temporal_coercion pairs Time32/Time64 with Date32/Date64 but has no rule for two time types. Timestamps avoid the problem because temporal_coercion_nonstrict_timezone unifies their units with timeunit_coercion. Comparison, IN, UNION, and coalesce coercion all reach temporal_coercion, so a matching time rule there would fix every query above. Time - Time already works across units through temporal_math_coercion and would not change.
#27316 (support TIME(p)) also makes this reachable from SQL type names alone, since CAST(x AS TIME(6)) or a column declared TIME(0) cannot be compared with plain TIME. @alamb suggested tracking it separately: https://github.com/apache/datafusion/pull/27316#discussion_r4538803450
Reproduced on main at 64c29642d. branch-56 and 55.2.0 have no time rule in temporal_coercion either. #27316 has been requested for 56, so it would help to backport this fix with it.
Willingness to contribute
I plan to contribute a fix for this bug independently
- 主要語言
- Rust
- 星號
- 9.6k
- 分支
- 2.6k
- 平均合併
- 3 天 4 小時
- 30 天內合併 PR
- 345
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
apache/datafusion 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
apache/datafusion#27315 · 2 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
apache/datafusion#27094 · 1 則留言 ·
維護者通常 1 天內回覆
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yaml可能已有人在做 @jonasHanhan 於 9 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
apache/datafusion#27059 ·
維護者通常 1 天內回覆
-
`ProjectionExprs::project_statistics` computes approximate `Statistics::total_byte_size` ignoring column stats可能已有人在做 @joseph-isaacs 於 10 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
apache/datafusion#27050 ·
維護者通常 1 天內回覆
-
physical-plan: decoding an Unnest or Explain node with an unset field panics可能已有人在做 @geoHeil 於 9 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
apache/datafusion#26999 · 1 則留言 ·
維護者通常 1 天內回覆
查看 apache/datafusion 的全部 Issue
相似的 Issue
-
P3
難度 2/5 1-3 小時 新手友好度 70/100
HerringtonDarkholme/hd-lang#1770 ·
維護者通常 1 天內回覆
-
needs triage
難度 2/5 1-3 小時 新手友好度 85/100
pbakaus/impeccable#1436 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
jonathanong/no-mistakes#3332 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
swc-project/swc-next-issues#310 ·
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
swc-project/swc-ai-issues#653 ·