Support TIME input in `hour`, `minute`, `second`, `extract` and `date_part`
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
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
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.
- Lenguaje dominante
- Rust
- Estrellas
- 7
- Forks
- 15
- Merge medio
- 16 h 43 min
- PR fusionados (30 d)
- 26
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/datafusion-spark
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
apache/datafusion-spark#287 ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
apache/datafusion-spark#266 ·
Los mantenedores suelen responder en 1 día
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the intervalPosiblemente ocupada @Subodh-17 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/datafusion-spark#109 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 18/100
apache/datafusion-spark#299 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
apache/datafusion-spark#298 ·
Los mantenedores suelen responder en 1 día
Todos los issues de apache/datafusion-spark
Issues similares
-
comp-rbac
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ClickHouse/ClickHouse#131875 ·
Los mantenedores suelen responder en 1 día
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesPosiblemente ocupada @Borg93 la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
lance-format/lance#11117 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
storytold/photocraft#15232 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
forge: fork preflight reads still send `requireCanonical: false`, which Rootstock rejects (-32603)Posiblemente ocupada @Ynyesto la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
foundry-rs/foundry#18485 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
bondybondbond/rushcut#238 · 1 comentario ·