dongjoon-hyun commented on a change in pull request #27612: 
[SPARK-30857][SQL][2.4] Fix truncations of timestamps before the epoch to hours 
and days
URL: https://github.com/apache/spark/pull/27612#discussion_r380444937
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/DateFunctionsSuite.scala
 ##########
 @@ -729,4 +729,17 @@ class DateFunctionsSuite extends QueryTest with 
SharedSQLContext {
         Row(Timestamp.valueOf("2015-07-24 07:00:00")),
         Row(Timestamp.valueOf("2015-07-24 22:00:00"))))
   }
+
+  test("SPARK-30857: truncate timestamps before the epoch to hours and days") {
+    def checkTrunc(level: String, expected: String): Unit = {
+      val df = Seq("1961-04-12 00:01:02.345")
+        .toDF()
+        .select($"value".cast("timestamp").as("ts"))
+        .select(date_trunc(level, $"ts").cast("string"))
+      checkAnswer(df, Row(expected))
+    }
+
+    checkTrunc("HOUR", "1961-04-12 00:00:00")
+    checkTrunc("DAY", "1961-04-12 00:00:00")
 
 Review comment:
   ~nit. If possible, can we have additional test statements for `minute` and 
`second` together below line 743 to make it sure?~
   Never mind. I missed the other PR which landed already on `branch-2.4`.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to