MaxGekk commented on code in PR #56733:
URL: https://github.com/apache/spark/pull/56733#discussion_r3467474626
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala:
##########
@@ -2625,6 +2625,62 @@ class DateExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
MakeTimestampNTZNanos(dateLit(date), timeNanos, 7).canonicalized)
}
+ test("SPARK-57660: make timestamp_ltz from date and time") {
+ Seq(
+ ("2025-06-20", "15:20:30.123456", "America/Los_Angeles", LA),
+ ("2025-06-20", "15:20:30.123456", "+01:00", CET)
+ ).foreach { case (date, time, tz, zoneId) =>
+ // The local date-time is interpreted in the given zone to produce the
instant.
+ checkEvaluation(
+ MakeTimestampLTZ(dateLit(date), timeLit(time), Option(tz)),
+ timestampToMicros(s"${date}T${time}", zoneId))
+ }
+ // Null inputs propagate to a null result.
+ checkEvaluation(
+ MakeTimestampLTZ(Literal(null, DateType), timeLit("15:20:30"), UTC_OPT),
null)
+ checkEvaluation(
+ MakeTimestampLTZ(dateLit("2025-06-20"), Literal(null, TimeType()),
UTC_OPT), null)
+ // The result type is the micro TIMESTAMP_LTZ (TimestampType).
+ assert(MakeTimestampLTZ(dateLit("2025-06-20"), timeLit("15:20:30"),
UTC_OPT).dataType ===
+ TimestampType)
+ }
+
+ test("SPARK-57660: make nanosecond timestamp_ltz from date and time") {
+ val date = "2025-06-20"
+ val timeNanos = Literal.create(localTime(15, 20, 30, 123456, 789),
TimeType(9))
+ Seq("America/Los_Angeles" -> LA, "+01:00" -> CET).foreach { case (tz,
zoneId) =>
+ val micros = timestampToMicros(s"${date}T15:20:30.123456", zoneId)
+ // Precision 9 preserves all sub-microsecond digits; lower precisions
floor them.
+ checkEvaluation(MakeTimestampLTZNanos(dateLit(date), timeNanos, 9,
Option(tz)),
+ TimestampNanosVal.fromParts(micros, 789.toShort))
+ checkEvaluation(MakeTimestampLTZNanos(dateLit(date), timeNanos, 8,
Option(tz)),
+ TimestampNanosVal.fromParts(micros, 780.toShort))
+ checkEvaluation(MakeTimestampLTZNanos(dateLit(date), timeNanos, 7,
Option(tz)),
+ TimestampNanosVal.fromParts(micros, 700.toShort))
+ }
+ // Pre-epoch date.
+ val preEpochMicros = timestampToMicros("1969-12-31T23:59:59.123456", UTC)
+ checkEvaluation(
+ MakeTimestampLTZNanos(dateLit("1969-12-31"),
+ Literal.create(localTime(23, 59, 59, 123456, 789), TimeType(9)), 9,
UTC_OPT),
+ TimestampNanosVal.fromParts(preEpochMicros, 789.toShort))
+ // Null inputs propagate to a null result.
+ checkEvaluation(MakeTimestampLTZNanos(Literal(null, DateType), timeNanos,
9, UTC_OPT), null)
+ checkEvaluation(
+ MakeTimestampLTZNanos(dateLit(date), Literal(null, TimeType(9)), 9,
UTC_OPT), null)
+ // The result type carries the requested nanosecond precision.
+ assert(MakeTimestampLTZNanos(dateLit(date), timeNanos, 7,
UTC_OPT).dataType ===
+ TimestampLTZNanosType(7))
+ // The precision participates in equality and canonicalization: builders
that differ only in
+ // precision are distinct, so two casts to different TIMESTAMP_LTZ(q) are
never conflated.
+ assert(MakeTimestampLTZNanos(dateLit(date), timeNanos, 9, UTC_OPT) !=
+ MakeTimestampLTZNanos(dateLit(date), timeNanos, 7, UTC_OPT))
+ assert(MakeTimestampLTZNanos(dateLit(date), timeNanos, 9,
UTC_OPT).canonicalized ==
+ MakeTimestampLTZNanos(dateLit(date), timeNanos, 9,
UTC_OPT).canonicalized)
+ assert(MakeTimestampLTZNanos(dateLit(date), timeNanos, 9,
UTC_OPT).canonicalized !=
+ MakeTimestampLTZNanos(dateLit(date), timeNanos, 7,
UTC_OPT).canonicalized)
+ }
+
Review Comment:
Added a DST gap/overlap test. Since the `TIME -> TIMESTAMP_LTZ` cast takes
its date from `CURRENT_DATE`, a Cast-level transition round-trip isn't
deterministic, so I put the coverage on the `MakeTimestampLTZ` /
`MakeTimestampLTZNanos` builders (the zone-conversion branch that
`ComputeCurrentTime` rewrites the cast into), using explicit transition dates:
the LA spring-forward gap (2020-03-08 02:30 -> shifted to 03:30 PDT,
sub-microsecond digits preserved) and the fall-back overlap (2020-11-01 01:30
-> earlier offset, UTC-7). New test `"SPARK-57660: make timestamp_ltz across
DST transitions"` in `DateExpressionsSuite`.
--
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]