cloud-fan commented on a change in pull request #27537: 
[SPARK-30668][SQL][FOLLOWUP] Raise exception instead of silent change for new 
DateFormatter
URL: https://github.com/apache/spark/pull/27537#discussion_r387601052
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala
 ##########
 @@ -57,6 +60,27 @@ trait DateTimeFormatterHelper {
     }
     formatter
   }
+
+  // When legacy time parser policy set to EXCEPTION, check whether we will 
get different results
+  // between legacy format and new format. For legacy parser, 
DateTimeParseException will not be
+  // thrown. On the contrary, if the legacy policy set to CORRECTED, 
DateTimeParseException will
+  // address by the caller side.
+  protected def checkDiffResult[T](
+      s: String, legacyParseFunc: String => T): PartialFunction[Throwable, T] 
= {
+    case e: DateTimeParseException if SQLConf.get.legacyTimeParserPolicy == 
EXCEPTION =>
+      val res = try {
+        Some(legacyParseFunc(s))
+      } catch {
+        case _: Throwable => None
+      }
+      if (res.nonEmpty) {
+        throw new SparkUpgradeException("3.0", s"Set 
${SQLConf.LEGACY_TIME_PARSER_POLICY.key} to " +
 
 Review comment:
   We should explain what happened.
   
   `Fail to parse '$s' in the new parser. You can set ... to LEGACY to restore 
..., or set it to CORRECTED and treat it as an invalid datetime string.`

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