Support TIME input in `hour`, `minute`, `second`, `extract` and `date_part`

未关闭
#270 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust, sql
领域
databases

调研方向

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 内容生成。

描述

enhancement

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, minute and second are ExpressionBuilders that pick the TIME expression when the argument is a TimeType.
    EXTRACT and date_part go through TimePart.parseExtractField, which accepts HOUR/H/HOURS/HR/HRS,
    MINUTE/M/MIN/MINS/MINUTES and SECOND/S/SEC/SECONDS/SECS. Any other field fails analysis.
  • SecondsOfTimeWithFraction truncates the fraction to the precision p of TIME(p) (DateTimeUtils.getSecondsOfTimeWithFraction).
  • All of these are RuntimeReplaceable and become StaticInvoke calls into DateTimeUtils.
    The source is sql/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 DAY on 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, minute and second are in crates/spark/src/function/datetime/extract.rs, and date_part is 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-spark 的其他 Issue

查看 apache/datafusion-spark 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。