itholic commented on code in PR #45244:
URL: https://github.com/apache/spark/pull/45244#discussion_r1503550041


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/TimestampFormatterSuite.scala:
##########
@@ -502,4 +504,25 @@ class TimestampFormatterSuite extends 
DatetimeFormatterSuite {
     assert(formatter.parseOptional("9999-12-31 23:59:59.999").isEmpty)
     assert(formatter.parseWithoutTimeZoneOptional("9999-12-31 23:59:59.999", 
true).isEmpty)
   }
+
+  test("fail to parse string as TimestampNTZ with invalid format") {
+    val zoneId = ZoneId.systemDefault()
+    val locale = Locale.getDefault()
+    val formatter = new DefaultTimestampFormatter(
+      zoneId, locale, LENIENT_SIMPLE_DATE_FORMAT, isParsing = true)
+
+    val invalidTimestampStr = "2021-13-01T25:61:61"
+
+    checkError(
+      exception = intercept[SparkRuntimeException] {
+        formatter.parseWithoutTimeZone(invalidTimestampStr, allowTimeZone = 
false)

Review Comment:
   I just realized the comment from the source code below:
   
   ```
   * The formatter for timestamps which doesn't require users to specify a 
pattern. While formatting,
    * it uses the default pattern [[TimestampFormatter.defaultPattern()]]. In 
parsing, it follows
    * the CAST logic in conversion of strings to Catalyst's TimestampType.
   ```
   
   so I suspect that this cannot be reproduced from user space, so we should 
mark it as an internal error.



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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

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