You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/02/18 04:00:39 UTC

[GitHub] [spark] 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

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 statement for `minute` and `second` together to make it sure?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org