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

Abierto
#270 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
66/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, sql
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
7
Forks
15
Merge medio
16 h 43 min
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/datafusion-spark

Todos los issues de apache/datafusion-spark

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.