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



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -945,6 +934,36 @@ abstract class AnsiCastSuiteBase extends CastSuiteBase {
       cast("abcd", DecimalType(38, 1)),
       "invalid input syntax for type numeric")
   }
+
+  test("ANSI mode: cast string to timestamp with parse error") {
+    val currentAnsiEnabled = SQLConf.get.ansiEnabled
+    new ParVector(ALL_TIMEZONES.toVector).foreach { zid =>
+      def checkCastWithParseError(str: String): Unit = {
+        checkExceptionInExpression[DateTimeException](
+          cast(Literal(str), TimestampType, Option(zid.getId)),
+          s"Cannot cast $str to TimestampType.")
+      }
+
+      withSQLConf(SQLConf.ANSI_ENABLED.key -> currentAnsiEnabled.toString) {
+        checkCastWithParseError("123")
+        checkCastWithParseError("2015-03-18 123142")
+        checkCastWithParseError("2015-03-18T123123")
+        checkCastWithParseError("2015-03-18X")
+        checkCastWithParseError("2015/03/18")
+        checkCastWithParseError("2015.03.18")
+        checkCastWithParseError("20150318")
+        checkCastWithParseError("2015-031-8")
+        checkCastWithParseError("2015-03-18T12:03:17-0:70")
+      }
+    }
+  }
+
+  test("ANSI mode: timestamp type casting with parse error") {

Review comment:
       Why is this a separate test?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to