uros-b commented on code in PR #56616:
URL: https://github.com/apache/spark/pull/56616#discussion_r3444968795


##########
sql/core/src/test/scala/org/apache/spark/sql/TimestampNanosFunctionsSuiteBase.scala:
##########
@@ -481,6 +481,41 @@ abstract class TimestampNanosFunctionsSuiteBase extends 
SharedSparkSession {
       checkAnswer(ltz.select(unix_nanos(col("c"))), Row(null))
     }
   }
+
+  test("SPARK-57526: timestamp_nanos builds nanosecond-precision TIMESTAMP_LTZ 
values") {
+    // 1230219000123456789 ns since the epoch -> 2008-12-25 15:30:00.123456789 
UTC. The result is a
+    // TIMESTAMP_LTZ(9); collecting it yields the absolute Instant regardless 
of the session zone.
+    val nanos = 1230219000123456789L
+    val instant = Instant.parse("2008-12-25T15:30:00.123456789Z")
+    val sqlRes = spark.sql(s"SELECT timestamp_nanos($nanos)")
+    val colRes = spark.range(1).select(timestamp_nanos(lit(nanos)))
+    // The SQL and Scala Column API agree, return the expected instant, and 
keep the LTZ(9) type.
+    checkAnswer(sqlRes, colRes)
+    checkAnswer(sqlRes, Row(instant))
+    assert(sqlRes.schema.head.dataType === TimestampLTZNanosType(9))
+
+    // A BIGINT argument is implicitly cast to DECIMAL, so the integral 
literal works directly.

Review Comment:
   Nit: This comment seems inaccurate; the expression uses ExpectsInputTypes 
(not ImplicitCastInputTypes), so a BIGINT is not cast to DECIMAL — it goes 
through the dedicated IntegralType path (BigInteger.valueOf(... longValue())).



-- 
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]

Reply via email to