[
https://issues.apache.org/jira/browse/SPARK-54281?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Max Gekk updated SPARK-54281:
-----------------------------
Shepherd: Max Gekk
> Support cast from numeric types to time
> ---------------------------------------
>
> Key: SPARK-54281
> URL: https://issues.apache.org/jira/browse/SPARK-54281
> Project: Spark
> Issue Type: Sub-task
> Components: SQL
> Affects Versions: 4.1.0
> Reporter: Uroš Bojanić
> Priority: Major
> Labels: pull-request-available
>
> h2. What
> Support casting numeric types (integral and DECIMAL) to {{TIME}}, the inverse
> of the
> existing {{TIME -> numeric}} casts (SPARK-52619 / SPARK-52620).
> h2. Semantics
> Mirror the existing {{TIME -> numeric}} direction so the casts round-trip:
> * {{TIME -> integral}} is {{floor(nanos_of_day / 1e9)}} (seconds of day).
> Therefore
> {{integral -> TIME}} interprets the value as *seconds since midnight*:
> {{nanos_of_day = seconds * 1_000_000_000}}.
> * {{TIME -> DECIMAL}} encodes nanos-of-day as a decimal number of seconds.
> Therefore
> {{DECIMAL -> TIME}} interprets the value as *seconds since midnight with a
> fractional part*,
> scaled to nanoseconds and truncated to the target precision.
> h2. Range and error handling
> * Valid range is {{[0, 86400)}} seconds (i.e. {{00:00:00}} ..
> {{23:59:59.999999999}}).
> * ANSI mode: out-of-range or NULL-producing inputs raise the standard cast
> overflow error.
> * Non-ANSI mode: out-of-range inputs return NULL (mark the cast
> {{forceNullable}}).
> * FLOAT/DOUBLE are out of scope (consistent with TIME -> numeric, which only
> covers
> integral and DECIMAL).
> h2. Scope
> * {{Cast.canCast}}/{{canAnsiCast}} entries for {{NumericType -> TimeType}}.
> * Runtime + codegen paths in {{Cast.scala}} (reuse {{DateTimeUtils}} helpers).
> * Tests in {{CastSuiteBase}} (ANSI on/off) and SQL golden files; verify
> {{cast(cast(t as bigint) as time)}} round-trips.
> h2. Note
> Numeric <-> TIME is a Spark extension; the SQL standard does not define it.
> Keep behavior
> consistent with the already-merged TIME -> numeric direction.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]