Support TIME input in `hour`, `minute`, `second`, `extract` and `date_part`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in crates/spark/src/function/datetime/extract.rs for hour, minute and second, and date_part.rs for date_part; add the TimeType branches there. Use the Comet extract_date_part.rs implementation only as a reference for spark_seconds_of_time, then run the datetime-function tests for this crate. Done means matching Spark's golden results for NULL, midnight, 23:59:59.999999, TIME precisions 0 through 6, all field aliases, and an unsupported field such as DAY.
由索引模型根据 Issue 内容生成。
描述
Part of #178. Split out of #155, which was closed as a duplicate of #211 and #212.
What the functions do
Spark 4.1 added the TIME type, and the hour, minute and second functions accept it. datafusion-spark's hour, minute,
second and date_part don't accept TIME yet.
| Spark SQL | Spark expression (4.1) | Result |
|---|---|---|
hour(t), extract(HOUR FROM t) |
HoursOfTime |
INT |
minute(t), extract(MINUTE FROM t) |
MinutesOfTime |
INT |
second(t) |
SecondsOfTime |
INT (whole seconds) |
extract(SECOND FROM t), date_part('SECOND', t) |
SecondsOfTimeWithFraction |
DECIMAL(8,6) |
hour,minuteandsecondareExpressionBuilders that pick the TIME expression when the argument is aTimeType.
EXTRACTanddate_partgo throughTimePart.parseExtractField, which acceptsHOUR/H/HOURS/HR/HRS,
MINUTE/M/MIN/MINS/MINUTESandSECOND/S/SEC/SECONDS/SECS. Any other field fails analysis.SecondsOfTimeWithFractiontruncates the fraction to the precisionpofTIME(p)(DateTimeUtils.getSecondsOfTimeWithFraction).- All of these are
RuntimeReplaceableand becomeStaticInvokecalls intoDateTimeUtils.
The source issql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala.
Examples
From sql/core/src/test/resources/sql-tests/results/time.sql.out (Spark 4.1.1):
SELECT extract(HOUR FROM time'23:59:00.987654'); -- 23 (int)
SELECT extract(MINUTE FROM time'00:59:00.987654'); -- 59 (int)
SELECT extract(SECOND FROM time'00:59:00.987654'); -- 0.987654 (decimal(8,6))
SELECT extract(SECOND FROM cast('09:08:01.987654' AS time(0))); -- 1.000000
SELECT extract(SECOND FROM cast('09:08:01.987654' AS time(3))); -- 1.987000
SELECT extract(SECOND FROM cast('09:08:01.987654' AS time(6))); -- 1.987654
SELECT second(TIME'13:25:59.999999'); -- 59 (from the ExpressionDescription)
Comet implementation
Comet implements extract(SECOND FROM time) (spark_seconds_of_time). It takes the TIME value as
Time64(Nanosecond) and the precision as a literal, and returns DECIMAL(8,6):
Edge cases to test
- NULL input, midnight,
23:59:59.999999. - Every TIME precision from 0 to 6 for
extract(SECOND ...). - All the field aliases above, and an unsupported field such as
DAYon a TIME.
Differences across Spark versions
- TIME exists only in Spark 4.1 and later. In 3.4, 3.5 and 4.0 these functions take only timestamps (and strings cast to timestamps).
Implementation notes
- The existing
hour,minuteandsecondare incrates/spark/src/function/datetime/extract.rs, anddate_partis in
date_part.rs. Add TIME handling there rather than new functions. - #38 (
date_part('SECOND', ts)drops the fractional seconds) is the timestamp counterpart of the DECIMAL(8,6) result here.
This issue was generated by an LLM (Claude Code) from the Apache Spark source code, Spark's .sql.out golden files and
Comet's source. Please verify the details against Spark before relying on them.
- 主要语言
- Rust
- 星标
- 7
- 派生
- 15
- 平均合并
- 16 小时 43 分钟
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion-spark 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
apache/datafusion-spark#287 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 80/100
apache/datafusion-spark#266 ·
维护者通常 1 天内回复
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the interval可能已有人在做 @Subodh-17 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-spark#109 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 18/100
apache/datafusion-spark#299 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
apache/datafusion-spark#298 ·
维护者通常 1 天内回复
查看 apache/datafusion-spark 的全部 Issue
相似的 Issue
-
comp-rbac
难度 2/5 1-3 小时 新手友好度 68/100
ClickHouse/ClickHouse#131875 ·
维护者通常 1 天内回复
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indices可能已有人在做 @Borg93 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 75/100
lance-format/lance#11117 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
storytold/photocraft#15232 · 1 条评论 ·
维护者通常 1 天内回复
-
forge: fork preflight reads still send `requireCanonical: false`, which Rootstock rejects (-32603)可能已有人在做 @Ynyesto 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
foundry-rs/foundry#18485 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
bondybondbond/rushcut#238 · 1 条评论 ·