You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Max Gekk (Jira)" <ji...@apache.org> on 2026/07/01 14:26:00 UTC

[jira] [Created] (SPARK-57821) Support nanosecond-precision timestamps in date_trunc

Max Gekk created SPARK-57821:
--------------------------------

             Summary: Support nanosecond-precision timestamps in date_trunc
                 Key: SPARK-57821
                 URL: https://issues.apache.org/jira/browse/SPARK-57821
             Project: Spark
          Issue Type: Sub-task
          Components: SQL
    Affects Versions: 4.3.0
            Reporter: Max Gekk


This sub-task is part of the umbrella SPARK-56822 (timestamps with nanosecond precision).

h2. Problem
{{TruncTimestamp}} (datetimeExpressions.scala ~L2874-2900) declares {{inputTypes = Seq(StringType, TimestampType)}} and {{dataType = TimestampType}}, and evaluates via {{DateTimeUtils.truncTimestamp(Long, ...)}}. A {{TIMESTAMP_NTZ(p)}} / {{TIMESTAMP_LTZ(p)}} argument is implicitly cast to microsecond {{TimestampType}}, dropping {{nanosWithinMicro}} and forcing an LTZ result even for NTZ input. ({{trunc(date, ...)}} is date-only and out of scope.)

h2. Goal
{{date_trunc(fmt, ts_nanos)}} accepts nanosecond timestamps, returns the same nanosecond type/precision and family, and truncates correctly (units at or above SECOND zero the whole fraction including {{nanosWithinMicro}}; MICROSECOND zeroes {{nanosWithinMicro}}).

h2. Scope
Extend {{TruncTimestamp.inputTypes}} / {{dataType}} to accept {{AnyTimestampNanoType}}; add a nanosecond eval/codegen branch operating on {{TimestampNanosVal}}; add {{DateTimeUtils.truncTimestampNanos}} if needed; keep the format-unit list unchanged (optionally accept a no-op NANOSECOND unit).

h2. Acceptance criteria
* {{date_trunc('SECOND'|'MINUTE'|'HOUR'|'DAY'|...)}} over NTZ/LTZ nanos returns the same type with the fraction zeroed; {{date_trunc('MICROSECOND', ...)}} zeroes only {{nanosWithinMicro}}; NTZ stays NTZ, LTZ stays LTZ.

h2. Testing
{{DateExpressionsSuite}}; nanos golden files.

h2. Dependencies
None - independent.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org