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/06/10 08:17:48 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #28766: [SPARK-31939][SQL][test-java11] Fix Parsing day of year when year field pattern is missing

cloud-fan commented on a change in pull request #28766:
URL: https://github.com/apache/spark/pull/28766#discussion_r437944533



##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DatetimeFormatterSuite.scala
##########
@@ -21,11 +21,44 @@ import org.scalatest.Matchers
 
 import org.apache.spark.{SparkFunSuite, SparkUpgradeException}
 import org.apache.spark.sql.catalyst.plans.SQLHelper
+import org.apache.spark.sql.catalyst.util.DateTimeTestUtils.{date, UTC}
 
 trait DatetimeFormatterSuite extends SparkFunSuite with SQLHelper with Matchers {
   import DateTimeFormatterHelper._
   def checkFormatterCreation(pattern: String, isParsing: Boolean): Unit
 
+  private def dateFormatter(pattern: String): DateFormatter = {
+    DateFormatter(pattern, UTC, isParsing = true)
+  }
+
+  private def timestampFormatter(pattern: String): TimestampFormatter =
+    TimestampFormatter(pattern, UTC, isParsing = true)
+
+  protected def useDateFormatter: Boolean
+
+  private def assertEqual(pattern: String, datetimeStr: String, expected: Long): Unit = {
+    if (useDateFormatter) {
+      assert(dateFormatter(pattern).parse(datetimeStr) ===
+        DateTimeUtils.microsToEpochDays(expected, UTC))
+    } else {
+      assert(timestampFormatter(pattern).parse(datetimeStr) === expected)
+    }
+  }
+
+  private def assertError(pattern: String, datetimeStr: String, expectedMsg: String): Unit = {
+    val exception = if (useDateFormatter) {
+      intercept[Exception](dateFormatter(pattern).parse(datetimeStr))

Review comment:
       can we specify the exception class?




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



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