This is an automated email from the ASF dual-hosted git repository.

MaxGekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new dbea6d2f6e99 [SPARK-60743][SQL] Fix make_timestamp silently wrapping 
an out-of-range seconds value
dbea6d2f6e99 is described below

commit dbea6d2f6e993776074711936dfbbda80140aaf2
Author: Max Gekk <[email protected]>
AuthorDate: Tue Nov 10 04:42:52 2026 +0100

    [SPARK-60743][SQL] Fix make_timestamp silently wrapping an out-of-range 
seconds value
    
    ### What changes were proposed in this pull request?
    
    `make_timestamp`, `make_timestamp_ltz` and `make_timestamp_ntz` (the 
`MakeTimestamp` expression) build their result in 
`DateTimeExpressionUtils.makeTimestampMicros`. That method narrowed the 
unscaled seconds value, in microseconds, to an `int`:
    
    ```java
    // 8 digits cannot overflow Int.
    int totalMicros = (int) secAndMicros.toUnscaledLong();
    ```
    
    The comment dates from when the `sec` input was `DecimalType(8, 6)`. 
SPARK-36428 widened it to `DecimalType(16, 6)` so that integer seconds are 
accepted, and from then on the unscaled value can reach about 10^16, so the 
cast drops the high bits.
    
    This PR moves the split of the seconds into whole seconds and nanos, with 
the check that the whole seconds fit an `int` and are not negative before 
narrowing, from `DateTimeUtils.makeTime` into a shared helper, 
`DateTimeUtils.splitSecsAndMicros`, and calls it from `makeTimestampMicros` 
too. The helper returns the whole seconds and the nanos packed into a `long`, 
so nothing is allocated per row, and asserts the scale of 6 that the split 
relies on, for both callers. So `make_timestamp`  [...]
    
    ### Why are the changes needed?
    
    A seconds value 2^32 microseconds (4294.967296 seconds) away from a valid 
one wraps into that valid value and returns a wrong timestamp with no error, 
even with ANSI mode on:
    
    ```sql
    SELECT make_timestamp_ntz(2020, 1, 1, 0, 0, 4324.967296);
    -- 2020-01-01 00:00:30   (4324967296 - 2^32 = 30000000 micros)
    
    SELECT make_timestamp_ntz(2019, 6, 30, 23, 59, 4354.967296);
    -- 2019-07-01 00:00:00   (wraps to exactly 60 seconds and rolls over)
    
    SELECT make_timestamp_ntz(2020, 1, 1, 0, 0, -4264.967296);
    -- 2020-01-01 00:00:30
    ```
    
    A value of 61 seconds gives NULL with ANSI off and a 
`DATETIME_FIELD_OUT_OF_BOUNDS` error with ANSI on, and these values should too. 
Values whose wrapped result is still invalid, for example 3000 seconds, already 
fail, but the error reports the wrapped number (`Invalid value for 
SecondOfMinute (valid values 0 - 59): -1295`) rather than the input.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, a bug fix. The six- and seven-argument forms of `make_timestamp`, 
`make_timestamp_ltz` and `make_timestamp_ntz`, with seconds above 2147.483647 
or below -2147.483648, no longer return a wrapped timestamp. They now return 
NULL when ANSI mode is off and raise 
`DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION` when it is on, as 61 seconds 
does. `try_make_timestamp*` returns NULL for them. A value that wrapped into 
the fraction of the 60th second, such as 4354.967297, raised `INVALID_ [...]
    
    ### How was this patch tested?
    
    Added a test to `DateExpressionsSuite`. It checks seventeen cases against 
`TimestampType`, with and without a time zone argument (the seven-argument 
form), and `TimestampNTZType`, with ANSI on and off: 2147.483647 and 
2147.483648 (the largest micros that fit an int, and the first that do not), 
4324.967296 (wraps to 30 s), 4354.967296 (wraps to 60 s and rolls over), 
4354.967297 (wraps to 60.000001 s, which raised `INVALID_FRACTION_OF_SECOND`), 
3000 (wraps to a negative int), -4264.9672 [...]
    
    Added `make_timestamp(1, 1, 1, 1, 1, 4324.967296)` and the same 
`try_make_timestamp` to `timestamp.sql`, which pin the error with ANSI on, NULL 
with ANSI off, and NULL from `try_make_timestamp` end to end, and the same 
`make_timestamp_ltz` and `make_timestamp_ntz` calls to `timestamp-ltz.sql` and 
`timestamp-ntz.sql`, and regenerated their golden files (`timestamp.sql.out`, 
`nonansi/`, `timestampNTZ/` with and without ANSI, `datetime-legacy.sql.out`, 
`timestamp-ltz.sql.out` and `timest [...]
    
    ```
    build/sbt 'catalyst/testOnly *DateExpressionsSuite *DateTimeUtilsSuite 
*TimeExpressionsSuite'
    build/sbt 'sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z 
timestamp -z datetime -z time.sql'
    ```
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Opus 5.5)
    
    Closes #59955 from MaxGekk/SPARK-make-timestamp-sec-overflow.
    
    Authored-by: Max Gekk <[email protected]>
    Signed-off-by: Max Gekk <[email protected]>
    
    
    skip-checks: true
---
 docs/sql-migration-guide.md                        |  1 +
 .../expressions/DateTimeExpressionUtils.java       | 28 +++++-----
 .../spark/sql/catalyst/util/DateTimeUtils.scala    | 56 ++++++++++++-------
 .../expressions/DateExpressionsSuite.scala         | 63 ++++++++++++++++++++++
 .../sql/catalyst/util/DateTimeUtilsSuite.scala     |  8 +++
 .../analyzer-results/datetime-legacy.sql.out       | 14 +++++
 .../analyzer-results/nonansi/timestamp.sql.out     | 14 +++++
 .../analyzer-results/timestamp-ltz.sql.out         |  7 +++
 .../analyzer-results/timestamp-ntz.sql.out         |  7 +++
 .../sql-tests/analyzer-results/timestamp.sql.out   | 14 +++++
 .../timestampNTZ/timestamp-ansi.sql.out            | 14 +++++
 .../timestampNTZ/timestamp.sql.out                 | 14 +++++
 .../resources/sql-tests/inputs/timestamp-ltz.sql   |  2 +
 .../resources/sql-tests/inputs/timestamp-ntz.sql   |  2 +
 .../test/resources/sql-tests/inputs/timestamp.sql  |  3 ++
 .../sql-tests/results/datetime-legacy.sql.out      | 23 ++++++++
 .../sql-tests/results/nonansi/timestamp.sql.out    | 16 ++++++
 .../sql-tests/results/timestamp-ltz.sql.out        | 15 ++++++
 .../sql-tests/results/timestamp-ntz.sql.out        | 15 ++++++
 .../resources/sql-tests/results/timestamp.sql.out  | 23 ++++++++
 .../results/timestampNTZ/timestamp-ansi.sql.out    | 23 ++++++++
 .../results/timestampNTZ/timestamp.sql.out         | 16 ++++++
 22 files changed, 347 insertions(+), 31 deletions(-)

diff --git a/docs/sql-migration-guide.md b/docs/sql-migration-guide.md
index 9d08a61d7460..5fa6049d6838 100644
--- a/docs/sql-migration-guide.md
+++ b/docs/sql-migration-guide.md
@@ -29,6 +29,7 @@ license: |
 
 ## Upgrading from Spark SQL 4.3 to 4.4
 
+- Since Spark 4.4, `make_timestamp`, `make_timestamp_ltz` and 
`make_timestamp_ntz` return `NULL` for a seconds value above 2147.483647 or 
below -2147.483648, or raise `DATETIME_FIELD_OUT_OF_BOUNDS` when 
`spark.sql.ansi.enabled` is `true`, as they do for other out-of-range seconds 
such as 61; `try_make_timestamp`, `try_make_timestamp_ltz` and 
`try_make_timestamp_ntz` return `NULL`. Previously, such a value wrapped around 
modulo 2^32 microseconds and could return a wrong timestamp, for exa [...]
 - Since Spark 4.4, dividing an ANSI interval by a number raises 
`INTERVAL_ARITHMETIC_OVERFLOW.WITH_SUGGESTION` (SQLSTATE 22015) whenever the 
result does not fit the interval type, in every evaluation mode. Previously, 
dividing the minimum year-month or day-time interval by `-1` raised 
`ARITHMETIC_OVERFLOW` (SQLSTATE 22003) in generated code, and dividing an 
interval by a decimal or a floating-point number whose quotient, once rounded, 
does not fit the type, or is infinite, raised a `java [...]
 - Since Spark 4.4, when a file source reads a partition column with a 
user-specified `DECIMAL` type from directory names, it converts each value to 
the precision and scale of that type, rounding half up as `CAST` does. 
Previously, the vectorized Parquet and ORC readers applied the declared scale 
to the digits in the directory name without an error, for example `d=1.5` read 
as `DECIMAL(10,2)` returned `0.15`. Data derived from affected query results 
may need to be recomputed. A value that [...]
 - Since Spark 4.4, when a file source reads a partition column with a 
user-specified `TINYINT` or `SMALLINT` type from directory names, a value out 
of the range of that type fails with `INVALID_PARTITION_VALUE` regardless of 
`spark.sql.ansi.enabled`, as it does for `INT`. Previously, the value wrapped 
around without an error, for example `b=300` read as `TINYINT` returned `44`. 
Data derived from affected query results may need to be recomputed. To get 
`NULL` for such a value, set `spark. [...]
diff --git 
a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/DateTimeExpressionUtils.java
 
b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/DateTimeExpressionUtils.java
index 748644fc093a..4a370aab5268 100644
--- 
a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/DateTimeExpressionUtils.java
+++ 
b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/DateTimeExpressionUtils.java
@@ -24,7 +24,6 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 
 import org.apache.spark.SparkDateTimeException;
-import org.apache.spark.sql.catalyst.util.DateTimeConstants;
 import org.apache.spark.sql.catalyst.util.DateTimeUtils;
 import org.apache.spark.sql.catalyst.util.IntervalUtils;
 import org.apache.spark.sql.catalyst.util.TimestampFormatter;
@@ -87,21 +86,26 @@ public final class DateTimeExpressionUtils {
    * (no zone applied); otherwise {@code zoneId} is used to resolve the 
instant.
    *
    * <p>This is the shared, exception-raising core used by both the eval and
-   * codegen paths. It throws {@link SparkDateTimeException} for an invalid
-   * fraction-of-second and {@link DateTimeException} for an invalid
-   * year/month/day/hour/min combination; callers decide how to translate 
those.
+   * codegen paths. It throws {@link DateTimeException} for seconds that are
+   * negative or whose whole seconds exceed {@code Integer.MAX_VALUE} 
(2147483648
+   * or more), before the other fields are checked; then
+   * {@link SparkDateTimeException} for an invalid fraction-of-second, a value
+   * between 60 and 61 seconds, still before the other fields; and otherwise
+   * {@link DateTimeException} for an invalid year/month/day/hour/min/second
+   * combination, 61 seconds included, in the order of the fields; callers 
decide
+   * how to translate those.
    */
   public static long makeTimestampMicros(
       int year, int month, int day, int hour, int min,
       Decimal secAndMicros, ZoneId zoneId, boolean timestampNTZ) {
-    assert secAndMicros.scale() == 6 :
-      "Seconds fraction must have 6 digits for microseconds but got " + 
secAndMicros.scale();
-    // 8 digits cannot overflow Int.
-    int totalMicros = (int) secAndMicros.toUnscaledLong();
-    int microsPerSecond = (int) DateTimeConstants.MICROS_PER_SECOND;
-    int nanosPerMicros = (int) DateTimeConstants.NANOS_PER_MICROS;
-    int seconds = Math.floorDiv(totalMicros, microsPerSecond);
-    int nanos = Math.floorMod(totalMicros, microsPerSecond) * nanosPerMicros;
+    // The seconds are DecimalType(16, 6), so their whole seconds can exceed 
an int. The split
+    // rejects such seconds, and negative ones, before narrowing, as make_time 
does; see
+    // DateTimeUtils.splitSecsAndMicros for the error message, the order of 
these checks and
+    // the packing of the seconds and the nanos. The 60-second branch below 
runs next, before
+    // LocalDateTime.of checks the other fields.
+    long secs = DateTimeUtils.splitSecsAndMicros(secAndMicros);
+    int seconds = (int) (secs >> 32);
+    int nanos = (int) secs;
     LocalDateTime ldt;
     if (seconds == 60) {
       if (nanos == 0) {
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
index a9a89780bec7..47f7e3df82d5 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
@@ -1105,6 +1105,41 @@ object DateTimeUtils extends SparkDateTimeUtils {
     }
   }
 
+  /**
+   * Splits the seconds of a minute with a fraction of 6 digits (microseconds) 
into the whole
+   * seconds and the nanos of the second, as `LocalTime.of` and 
`LocalDateTime.of` take them,
+   * packed into a long, the seconds in the high 32 bits and the nanos in the 
low 32 bits, so
+   * that nothing is allocated per row: `(packed >> 32).toInt` and 
`packed.toInt`.
+   *
+   * The whole seconds are checked to be in the int range and not negative 
before they are
+   * narrowed. A value outside of the int range would overflow when converted 
from long to int,
+   * and could produce an int in the valid seconds range and return a wrong 
value, or a misleading
+   * error message. A negative value is rejected here for a better error 
message: `Math.floorDiv`
+   * gets the next lower integer for it, so the full seconds would not match 
the value given.
+   * The message is the one that `LocalTime.of` and `LocalDateTime.of` throw 
for invalid seconds,
+   * with the seconds given, truncated towards zero, or in full for a value 
between -1 and 0,
+   * which the truncation would show as the valid 0. Any other value, such as 
61 seconds, is
+   * left to them, which check their fields in order, so an invalid date or 
hour is reported
+   * before such seconds, while a negative value, or one whose whole seconds 
exceed
+   * `Int.MaxValue` (2147483648 or more; 2147483647.5 passes), is reported 
first.
+   */
+  def splitSecsAndMicros(secsAndMicros: Decimal): Long = {
+    assert(secsAndMicros.scale == 6)
+    val unscaledSecFrac = secsAndMicros.toUnscaledLong
+    val fullSecs = Math.floorDiv(unscaledSecFrac, MICROS_PER_SECOND)
+    if (fullSecs > Int.MaxValue || fullSecs < 0) {
+      val shown = if (fullSecs == -1 && secsAndMicros.toLong == 0) {
+        secsAndMicros.toJavaBigDecimal.stripTrailingZeros.toPlainString
+      } else {
+        secsAndMicros.toLong.toString
+      }
+      throw new DateTimeException(
+        s"Invalid value for SecondOfMinute (valid values 0 - 59): $shown")
+    }
+    val nanos = Math.floorMod(unscaledSecFrac, MICROS_PER_SECOND) * 
NANOS_PER_MICROS
+    (fullSecs << 32) | nanos
+  }
+
   /**
    * Converts separate time fields in a long that represents nanoseconds since 
the start of
    * the day
@@ -1115,25 +1150,8 @@ object DateTimeUtils extends SparkDateTimeUtils {
    */
   def makeTime(hours: Int, minutes: Int, secsAndMicros: Decimal): Long = {
     try {
-      val unscaledSecFrac = secsAndMicros.toUnscaledLong
-      val fullSecs = Math.floorDiv(unscaledSecFrac, MICROS_PER_SECOND)
-      // The greater than Int.MaxValue check is needed for the case where the 
full seconds is
-      // outside of the int range. This will overflow when full seconds is 
converted from
-      // long to int. The overflow could produce an int in the valid seconds 
range and return a
-      // wrong value. For overflow values outside of the valid seconds range, 
it would result in a
-      // misleading error message.
-      // The negative check is needed to throw a better error message. In the 
negative case,
-      // Math.floorDiv gets the next lower negative integer so the full second 
value in the
-      // original decimal will not match what is in the error message.
-      if (fullSecs > Int.MaxValue || fullSecs < 0) {
-        // Make this error message consistent with what is thrown by 
LocalTime.of when the
-        // seconds are invalid
-        throw new DateTimeException(
-          s"Invalid value for SecondOfMinute (valid values 0 - 59): 
${secsAndMicros.toLong}")
-      }
-
-      val nanos = Math.floorMod(unscaledSecFrac, MICROS_PER_SECOND) * 
NANOS_PER_MICROS
-      val lt = LocalTime.of(hours, minutes, fullSecs.toInt, nanos.toInt)
+      val secs = splitSecsAndMicros(secsAndMicros)
+      val lt = LocalTime.of(hours, minutes, (secs >> 32).toInt, secs.toInt)
       localTimeToNanos(lt)
     } catch {
       case e @ (_: DateTimeException | _: ArithmeticException) =>
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
index 0e7688a14673..cacbfd9a3193 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
@@ -1599,6 +1599,69 @@ class DateExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
     }
   }
 
+  test("SPARK-60743: make_timestamp rejects out-of-range seconds instead of 
wrapping them") {
+    // The seconds input is DecimalType(16, 6), so its unscaled micros can 
exceed an int.
+    // Each value below must fail like 61 seconds does instead of wrapping 
modulo 2^32. The
+    // error shows the seconds given, truncated towards zero, as make_time 
reports them, or in
+    // full for a value between -1 and 0, which the truncation would show as 
the valid 0.
+    def secondOfMinute(shown: String): String =
+      s"Invalid value for SecondOfMinute (valid values 0 - 59): $shown"
+    val monthOfYear = "Invalid value for MonthOfYear (valid values 1 - 12): 13"
+    val outOfRangeSeconds = Seq(
+      // (year, month, day, hour, min, sec, the range message of the error)
+      // The largest micros that fit an int, and the first that do not.
+      (2020, 1, 1, 0, 0, "2147.483647", secondOfMinute("2147")),
+      (2020, 1, 1, 0, 0, "2147.483648", secondOfMinute("2147")),
+      // 4324967296 - 2^32 = 30000000 micros, which would read as 30 seconds.
+      (2020, 1, 1, 0, 0, "4324.967296", secondOfMinute("4324")),
+      // 4354967296 - 2^32 = 60000000 micros, which would roll over to the 
next minute.
+      (2019, 6, 30, 23, 59, "4354.967296", secondOfMinute("4354")),
+      // 4354967297 - 2^32 = 60000001 micros, which raised 
INVALID_FRACTION_OF_SECOND.
+      (2019, 6, 30, 23, 59, "4354.967297", secondOfMinute("4354")),
+      // 3000000000 micros would wrap to a negative int.
+      (2020, 1, 1, 0, 0, "3000", secondOfMinute("3000")),
+      // A negative value whose micros would wrap to 30 seconds.
+      (2020, 1, 1, 0, 0, "-4264.967296", secondOfMinute("-4264")),
+      // Values between -1 and 0, shown in full.
+      (2020, 1, 1, 0, 0, "-0.5", secondOfMinute("-0.5")),
+      (2020, 1, 1, 0, 0, "-0.000001", secondOfMinute("-0.000001")),
+      // The largest and the smallest DecimalType(16, 6) values: even their 
whole seconds do
+      // not fit an int.
+      (2020, 1, 1, 0, 0, "9999999999.999999", secondOfMinute("9999999999")),
+      (2020, 1, 1, 0, 0, "-9999999999.999999", secondOfMinute("-9999999999")),
+      // A small out-of-range value, for comparison.
+      (2020, 1, 1, 0, 0, "61", secondOfMinute("61")),
+      // With an invalid month: a negative value, or one whose whole seconds 
exceed Int.MaxValue,
+      // is reported before the month, as make_time does, and any other 
out-of-range value after
+      // it, a value between 60 and 61 seconds excepted, whose fraction is 
reported first.
+      (2020, 13, 1, 0, 0, "-1", secondOfMinute("-1")),
+      (2020, 13, 1, 0, 0, "61", monthOfYear),
+      (2020, 13, 1, 0, 0, "2147483647", monthOfYear),
+      (2020, 13, 1, 0, 0, "2147483647.5", monthOfYear),
+      (2020, 13, 1, 0, 0, "2147483648", secondOfMinute("2147483648")))
+    for {
+      dataType <- Seq(TimestampType, TimestampNTZType)
+      // The seven-argument form, with a time zone, for make_timestamp and 
make_timestamp_ltz.
+      timezone <- if (dataType == TimestampType) Seq(None, 
Some(Literal("UTC"))) else Seq(None)
+      ansi <- Seq(true, false)
+      (year, month, day, hour, min, sec, rangeMessage) <- outOfRangeSeconds
+    } {
+      val expr = MakeTimestamp(Literal(year), Literal(month), Literal(day), 
Literal(hour),
+        Literal(min), Literal(Decimal(BigDecimal(sec), 16, 6)), timezone = 
timezone,
+        timeZoneId = Some("UTC"), failOnError = ansi, dataType = dataType)
+      withClue(s"$dataType, timezone = $timezone, ansi = $ansi, sec = $sec: ") 
{
+        if (ansi) {
+          checkErrorInExpression[SparkDateTimeException](
+            expr,
+            condition = "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+            parameters = Map("rangeMessage" -> rangeMessage))
+        } else {
+          checkEvaluation(expr, null)
+        }
+      }
+    }
+  }
+
   test("ISO 8601 week-numbering year") {
     checkEvaluation(YearOfWeek(MakeDate(Literal(2006), Literal(1), 
Literal(1))), 2005)
     checkEvaluation(YearOfWeek(MakeDate(Literal(2006), Literal(1), 
Literal(2))), 2006)
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
index 1d39e88d9d54..f9b0b5d13913 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
@@ -1787,6 +1787,14 @@ class DateTimeUtilsSuite extends SparkFunSuite with 
Matchers with SQLHelper {
         parameters = Map("rangeMessage" ->
           s"Invalid value for SecondOfMinute (valid values 0 - 59): 
${invalidSecond.toLong}"))
     }
+    // A value between -1 and 0 is shown in full, not truncated to the valid 0.
+    checkError(
+      exception = intercept[SparkDateTimeException] {
+        makeTime(hour, min, Decimal(-0.5, 16, 6))
+      },
+      condition = "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+      parameters = Map("rangeMessage" ->
+        "Invalid value for SecondOfMinute (valid values 0 - 59): -0.5"))
   }
 
   test("SPARK-51415: makeTimestamp with days, nanos, and zoneId") {
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/datetime-legacy.sql.out
 
b/sql/core/src/test/resources/sql-tests/analyzer-results/datetime-legacy.sql.out
index 17a71df4101f..12ccbe83ad53 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/datetime-legacy.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/datetime-legacy.sql.out
@@ -1113,6 +1113,20 @@ Project [make_timestamp(1, 1, 1, 1, 1, cast(999.999999 
as decimal(16,6)), None,
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), true, TimestampType) AS make_timestamp(1, 1, 
1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [try_make_timestamp(1, 1, 1, 1, 1, 4324.967296) AS 
try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/nonansi/timestamp.sql.out
 
b/sql/core/src/test/resources/sql-tests/analyzer-results/nonansi/timestamp.sql.out
index 2d7e8c0f5bbb..55f055ec7531 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/nonansi/timestamp.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/nonansi/timestamp.sql.out
@@ -157,6 +157,20 @@ Project [make_timestamp(1, 1, 1, 1, 1, cast(999.999999 as 
decimal(16,6)), None,
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), false, TimestampType) AS make_timestamp(1, 1, 
1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [try_make_timestamp(1, 1, 1, 1, 1, 4324.967296) AS 
try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ltz.sql.out 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ltz.sql.out
index cc6ff0da5f79..48acf38d2be6 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ltz.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ltz.sql.out
@@ -47,6 +47,13 @@ Project [make_timestamp_ltz(2021, 7, 11, 6, 30, cast(60.007 
as decimal(16,6)), N
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp_ltz(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp_ltz(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), true, TimestampType) AS make_timestamp_ltz(1, 
1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ntz.sql.out 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ntz.sql.out
index 0b7ba782643a..149319ceccfe 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ntz.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ntz.sql.out
@@ -64,6 +64,13 @@ Project [make_timestamp_ntz(2021, 7, 11, 6, 30, cast(60.007 
as decimal(16,6)), N
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp_ntz(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp_ntz(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), true, TimestampNTZType) AS 
make_timestamp_ntz(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp_ntz(make_date(2021, 07, 11), make_time(6, 30, 45.678))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp.sql.out 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp.sql.out
index f6d88593a448..3a02ea796af1 100644
--- a/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp.sql.out
+++ b/sql/core/src/test/resources/sql-tests/analyzer-results/timestamp.sql.out
@@ -157,6 +157,20 @@ Project [make_timestamp(1, 1, 1, 1, 1, cast(999.999999 as 
decimal(16,6)), None,
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), true, TimestampType) AS make_timestamp(1, 1, 
1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [try_make_timestamp(1, 1, 1, 1, 1, 4324.967296) AS 
try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp-ansi.sql.out
 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp-ansi.sql.out
index 6db51872317c..2086dcc7d3ec 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp-ansi.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp-ansi.sql.out
@@ -158,6 +158,20 @@ Project [make_timestamp(1, 1, 1, 1, 1, cast(999.999999 as 
decimal(16,6)), None,
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), true, TimestampNTZType) AS make_timestamp(1, 
1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [try_make_timestamp(1, 1, 1, 1, 1, 4324.967296) AS 
try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query analysis
diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp.sql.out
 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp.sql.out
index afe3152de080..8cf74bd7b2f1 100644
--- 
a/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/timestamp.sql.out
@@ -158,6 +158,20 @@ Project [make_timestamp(1, 1, 1, 1, 1, cast(999.999999 as 
decimal(16,6)), None,
 +- OneRowRelation
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [make_timestamp(1, 1, 1, 1, 1, cast(4324.967296 as decimal(16,6)), 
None, Some(America/Los_Angeles), false, TimestampNTZType) AS make_timestamp(1, 
1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query analysis
+Project [try_make_timestamp(1, 1, 1, 1, 1, 4324.967296) AS 
try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)#x]
++- OneRowRelation
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query analysis
diff --git a/sql/core/src/test/resources/sql-tests/inputs/timestamp-ltz.sql 
b/sql/core/src/test/resources/sql-tests/inputs/timestamp-ltz.sql
index 6484383eabc0..d3dde5e338b0 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/timestamp-ltz.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/timestamp-ltz.sql
@@ -14,6 +14,8 @@ select to_timestamp_ltz(to_timestamp_ntz(null)), 
to_timestamp_ltz(to_timestamp_n
 SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 45.678);
 SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 45.678, 'CET');
 SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 60.007);
+-- SPARK-60743: seconds whose microseconds do not fit an int must not wrap to 
a valid value.
+SELECT make_timestamp_ltz(1, 1, 1, 1, 1, 4324.967296);
 
 -- TimestampLTZ date/time fields constructor
 SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678));
diff --git a/sql/core/src/test/resources/sql-tests/inputs/timestamp-ntz.sql 
b/sql/core/src/test/resources/sql-tests/inputs/timestamp-ntz.sql
index 0f9902cc4fee..91f9ef2a5307 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/timestamp-ntz.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/timestamp-ntz.sql
@@ -15,6 +15,8 @@ SELECT make_timestamp_ntz(2021, 07, 11, 6, 30, 45.678);
 -- make_timestamp_ntz should not accept time zone input
 SELECT make_timestamp_ntz(2021, 07, 11, 6, 30, 45.678, 'CET');
 SELECT make_timestamp_ntz(2021, 07, 11, 6, 30, 60.007);
+-- SPARK-60743: seconds whose microseconds do not fit an int must not wrap to 
a valid value.
+SELECT make_timestamp_ntz(1, 1, 1, 1, 1, 4324.967296);
 SELECT make_timestamp_ntz(make_date(2021, 07, 11), make_time(6, 30, 45.678));
 SELECT make_timestamp_ntz(NULL, TIME'00:00:00');
 SELECT make_timestamp_ntz(DATE'1970-01-01', NULL);
diff --git a/sql/core/src/test/resources/sql-tests/inputs/timestamp.sql 
b/sql/core/src/test/resources/sql-tests/inputs/timestamp.sql
index 6f8270f0c975..c7ae49d63ba7 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/timestamp.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/timestamp.sql
@@ -25,6 +25,9 @@ SELECT make_timestamp(1, 1, 1, 1, 1, null);
 SELECT make_timestamp(1, 1, 1, 1, 1, 59.999999);
 SELECT make_timestamp(1, 1, 1, 1, 1, 99.999999);
 SELECT make_timestamp(1, 1, 1, 1, 1, 999.999999);
+-- SPARK-60743: seconds whose microseconds do not fit an int must not wrap to 
a valid value.
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296);
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296);
 
 -- SPARK-51415: timestamp date constructor.
 SELECT make_timestamp(make_date(2021, 07, 11));
diff --git 
a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out 
b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
index aa877a43a859..d958d19cffd8 100644
--- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
@@ -1399,6 +1399,29 @@ org.apache.spark.SparkDateTimeException
 }
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkDateTimeException
+{
+  "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59): 
4324"
+  }
+}
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<try_make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp>
+-- !query output
+NULL
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query schema
diff --git 
a/sql/core/src/test/resources/sql-tests/results/nonansi/timestamp.sql.out 
b/sql/core/src/test/resources/sql-tests/results/nonansi/timestamp.sql.out
index 09fd5add2e0a..c692ef6f5437 100644
--- a/sql/core/src/test/resources/sql-tests/results/nonansi/timestamp.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/nonansi/timestamp.sql.out
@@ -180,6 +180,22 @@ struct<make_timestamp(1, 1, 1, 1, 1, 999.999999):timestamp>
 NULL
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp>
+-- !query output
+NULL
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<try_make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp>
+-- !query output
+NULL
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query schema
diff --git 
a/sql/core/src/test/resources/sql-tests/results/timestamp-ltz.sql.out 
b/sql/core/src/test/resources/sql-tests/results/timestamp-ltz.sql.out
index 6ec411a790eb..623e3b0e2e09 100644
--- a/sql/core/src/test/resources/sql-tests/results/timestamp-ltz.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/timestamp-ltz.sql.out
@@ -62,6 +62,21 @@ org.apache.spark.SparkDateTimeException
 }
 
 
+-- !query
+SELECT make_timestamp_ltz(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkDateTimeException
+{
+  "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59): 
4324"
+  }
+}
+
+
 -- !query
 SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678))
 -- !query schema
diff --git 
a/sql/core/src/test/resources/sql-tests/results/timestamp-ntz.sql.out 
b/sql/core/src/test/resources/sql-tests/results/timestamp-ntz.sql.out
index aff9b5abffd3..f15ee70a04d9 100644
--- a/sql/core/src/test/resources/sql-tests/results/timestamp-ntz.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/timestamp-ntz.sql.out
@@ -79,6 +79,21 @@ org.apache.spark.SparkDateTimeException
 }
 
 
+-- !query
+SELECT make_timestamp_ntz(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkDateTimeException
+{
+  "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59): 
4324"
+  }
+}
+
+
 -- !query
 SELECT make_timestamp_ntz(make_date(2021, 07, 11), make_time(6, 30, 45.678))
 -- !query schema
diff --git a/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out 
b/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
index 574b79595037..4696664fa1cb 100644
--- a/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
@@ -208,6 +208,29 @@ org.apache.spark.SparkDateTimeException
 }
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkDateTimeException
+{
+  "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59): 
4324"
+  }
+}
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<try_make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp>
+-- !query output
+NULL
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query schema
diff --git 
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
 
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
index 6b15e6911c85..4a7048d1a625 100644
--- 
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
@@ -208,6 +208,29 @@ org.apache.spark.SparkDateTimeException
 }
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkDateTimeException
+{
+  "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59): 
4324"
+  }
+}
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<try_make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp_ntz>
+-- !query output
+NULL
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query schema
diff --git 
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp.sql.out 
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp.sql.out
index 687d608212bb..f2436c1b1e35 100644
--- 
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp.sql.out
@@ -180,6 +180,22 @@ struct<make_timestamp(1, 1, 1, 1, 1, 
999.999999):timestamp_ntz>
 NULL
 
 
+-- !query
+SELECT make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp_ntz>
+-- !query output
+NULL
+
+
+-- !query
+SELECT try_make_timestamp(1, 1, 1, 1, 1, 4324.967296)
+-- !query schema
+struct<try_make_timestamp(1, 1, 1, 1, 1, 4324.967296):timestamp_ntz>
+-- !query output
+NULL
+
+
 -- !query
 SELECT make_timestamp(make_date(2021, 07, 11))
 -- !query schema


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to