AngersZhuuuu commented on a change in pull request #31971:
URL: https://github.com/apache/spark/pull/31971#discussion_r602380526



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1698,10 +1698,18 @@ class CastSuite extends CastSuiteBase {
 
   test("SPARK-34744: Improve error message for casting cause overflow error") {
     withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
-      val e = intercept[ArithmeticException] {
-        Cast(Literal(128), ByteType).eval()
+      val e1 = intercept[ArithmeticException] {
+        Cast(Literal(Byte.MaxValue.toInt + 1), ByteType).eval()
       }.getMessage
-      assert(e.contains("Casting 128 to tinyint causes overflow"))
+      assert(e1.contains("Casting 128 to tinyint causes overflow"))
+      val e2 = intercept[ArithmeticException] {
+        Cast(Literal(Short.MaxValue.toInt + 1), ShortType).eval()

Review comment:
       > nit: redundant toInt
   
   Done

##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1698,10 +1698,18 @@ class CastSuite extends CastSuiteBase {
 
   test("SPARK-34744: Improve error message for casting cause overflow error") {
     withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
-      val e = intercept[ArithmeticException] {
-        Cast(Literal(128), ByteType).eval()
+      val e1 = intercept[ArithmeticException] {
+        Cast(Literal(Byte.MaxValue.toInt + 1), ByteType).eval()
       }.getMessage
-      assert(e.contains("Casting 128 to tinyint causes overflow"))
+      assert(e1.contains("Casting 128 to tinyint causes overflow"))
+      val e2 = intercept[ArithmeticException] {
+        Cast(Literal(Short.MaxValue.toInt + 1), ShortType).eval()
+      }.getMessage
+      assert(e2.contains("Casting 32768 to smallint causes overflow"))
+      val e3 = intercept[ArithmeticException] {
+        Cast(Literal(Int.MaxValue.toLong + 1), IntegerType).eval()

Review comment:
       > nit:Int.MaxValue + 1L
   
   Done




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