yaooqinn commented on a change in pull request #28673:
URL: https://github.com/apache/spark/pull/28673#discussion_r432334147



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala
##########
@@ -118,6 +118,31 @@ trait DateTimeFormatterHelper {
         s"before Spark 3.0, or set to CORRECTED and treat it as an invalid 
datetime string.", e)
   }
 
+  // When legacy time parser policy set to EXCEPTION, check whether we will 
get different results
+  // between legacy formatter and new formatter. If new formatter fails but 
legacy formatter works,
+  // throw a SparkUpgradeException. On the contrary, if the legacy policy set 
to CORRECTED,
+  // DateTimeParseException will address by the caller side.
+  protected def checkDiffFormatResult[T <: Date](
+      d: T,
+      legacyFormatFunc: T => String): PartialFunction[Throwable, String] = {
+    case e if needConvertToSparkUpgradeException(e) =>
+      val resultCandidate = try {
+      legacyFormatFunc(d)
+    } catch {
+      case _: Throwable => throw e
+    }
+    throw new SparkUpgradeException("3.0", s"Fail to format '$resultCandidate' 
in the new" +
+      s" formatter. You can set ${SQLConf.LEGACY_TIME_PARSER_POLICY.key} to 
LEGACY to restore" +
+      s" the behavior before Spark 3.0, or set to CORRECTED and treat it as an 
invalid" +
+      s" datetime string.", e)
+  }
+
+  private def needConvertToSparkUpgradeException(e: Throwable): Boolean = e 
match {
+    case _: DateTimeException | _: ArrayIndexOutOfBoundsException

Review comment:
       Shall we use Nonfatal here?




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



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

Reply via email to