You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "stevomitric (via GitHub)" <gi...@apache.org> on 2026/07/13 13:27:49 UTC
[PR] [WIP][SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
stevomitric opened a new pull request, #57224:
URL: https://github.com/apache/spark/pull/57224
### What changes were proposed in this pull request?
Extend `date_trunc` (`TruncTimestamp`) to accept nanosecond-precision timestamps (`TIMESTAMP_NTZ(p)`/`TIMESTAMP_LTZ(p)`, p in [7, 9]) in addition to microsecond `TimestampType`. The result keeps the input's nanos type/family; truncation floors `epochMicros` (NTZ at UTC, LTZ in the session zone) and always zeroes the sub-microsecond remainder, since `date_trunc`'s finest unit is MICROSECOND. Adds `DateTimeUtils.truncTimestampNanos` delegating to the existing `truncTimestamp`.
### Why are the changes needed?
`date_trunc` previously narrowed a nanosecond argument to microseconds, dropping the sub-microsecond digits and forcing an LTZ result even for NTZ input.
### Does this PR introduce _any_ user-facing change?
Yes. `date_trunc(fmt, ts_nanos)` now returns the same nanosecond type/family with correct truncation (preview `spark.sql.timestampNanosTypes.enabled`).
### How was this patch tested?
`DateExpressionsSuite` and `timestamp-{ltz,ntz}-nanos.sql` golden files.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
Posted by "stevomitric (via GitHub)" <gi...@apache.org>.
stevomitric commented on PR #57224:
URL: https://github.com/apache/spark/pull/57224#issuecomment-4974054197
> @stevomitric Could you fix formatting
Fixed.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
Posted by "stevomitric (via GitHub)" <gi...@apache.org>.
stevomitric commented on PR #57224:
URL: https://github.com/apache/spark/pull/57224#issuecomment-4959579830
cc @MaxGekk, @cloud-fan PTAL.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on PR #57224:
URL: https://github.com/apache/spark/pull/57224#issuecomment-4966368699
@stevomitric Could you fix formatting:
```
Run ./dev/lint-scala
Scalastyle checks failed at following occurrences:
[error] /__w/spark/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala:655: File line length exceeds 100 characters
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #57224: [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc
URL: https://github.com/apache/spark/pull/57224
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57821][SQL] Support nanosecond-precision timestamps in date_trunc [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #57224:
URL: https://github.com/apache/spark/pull/57224#issuecomment-4992777605
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/f6a83dd22e3e436dd46c9166d8ea372167248ee5
- merged into branch-4.x https://github.com/apache/spark/commit/a12be2798596dee18370ad495b94f94d600fd02a
*Posted by `merge_spark_pr.py`*
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org