dongjoon-hyun opened a new pull request, #59600:
URL: https://github.com/apache/spark/pull/59600
### What changes were proposed in this pull request?
This PR aims to make `RowEncoder` keep the precision of `TIME(p)` by adding
the precision to `LocalTimeEncoder`.
- `LocalTimeEncoder` becomes `case class LocalTimeEncoder(precision: Int)`
whose type is `TimeType(precision)`.
- `RowEncoder` maps `TimeType(p)` to `LocalTimeEncoder(p)`.
- The encoders inferred from `java.time.LocalTime` still use `TIME(6)` via
`DEFAULT_LOCAL_TIME_ENCODER`.
### Why are the changes needed?
`RowEncoder` maps every `TIME(p)` to `LocalTimeEncoder` of `TIME(6)`, and
each array element is up-cast to the type of its encoder. Since `TIME(p)` can
be up-cast to `TIME(6)` only when `p` is 6, collecting an array of `TIME(p)`
fails for all other precisions.
```scala
scala> spark.sql("SELECT array(TIME '12:00:00.123456789')").collect()
org.apache.spark.sql.AnalysisException: [CANNOT_UP_CAST_DATATYPE] Cannot up
cast array element from "TIME(9)" to "TIME(6)".
```
### Does this PR introduce _any_ user-facing change?
Yes. Collecting an array of `TIME(p)` works for every precision, and
`Row.schema` of the collected rows reports `TIME(p)` instead of `TIME(6)`. Note
that the TIME type is disabled by default (`spark.sql.timeType.enabled`).
The bug exists since:
- Apache Spark [v4.1.0](https://github.com/apache/spark/releases/tag/v4.1.0)
(2025-12-11) for `TIME(0)` to `TIME(5)` (SPARK-51384)
- Apache Spark
[v4.3.0-rc1](https://github.com/apache/spark/releases/tag/v4.3.0-rc1)
(2026-08-31) for `TIME(7)` to `TIME(9)` (SPARK-57551)
### How was this patch tested?
Pass the CIs with the newly added test cases in `RowEncoderSuite`,
`DatasetSuite` and `ArrowEncoderSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]