uros-b commented on code in PR #56733:
URL: https://github.com/apache/spark/pull/56733#discussion_r3467022209
##########
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:
For tests in CastSuiteBase / DateExpressionsSuite: the TIME->TIMESTAMP_LTZ
forward direction (the zone-dependent path) is tested only under UTC; no DST
gap (spring-forward) / overlap (fall-back) round-trip case. Behavior is
parity-equivalent to existing makeTimestamp (LocalDateTime.atZone
post-transition offset), not a regression, but a spring-forward + fall-back
round-trip assertion in a non-UTC zone would close the only untested branch in
the family.
--
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]