cloud-fan commented on a change in pull request #25997: [SPARK-29326][SQL] ANSI 
store assignment policy: throw exception on casting failure
URL: https://github.com/apache/spark/pull/25997#discussion_r331001243
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala
 ##########
 @@ -634,6 +634,100 @@ class InsertSuite extends DataSourceTest with 
SharedSparkSession {
     }
   }
 
+  test("Throw exceptions on inserting out-of-range byte value with ANSI 
casting policy") {
+    withSQLConf(
+      SQLConf.STORE_ASSIGNMENT_POLICY.key -> 
SQLConf.StoreAssignmentPolicy.ANSI.toString) {
+      withTable("t") {
+        sql("create table t(b byte) using parquet")
+        val outOfRangeValue1 = Byte.MaxValue + 1
+        var msg = intercept[SparkException] {
+          sql(s"insert into t values($outOfRangeValue1)")
+        }.getCause.getMessage
+        assert(msg.contains(s"Casting $outOfRangeValue1 to byte causes 
overflow"))
+
+        val outOfRangeValue2 = Byte.MinValue - 1
+        msg = intercept[SparkException] {
+          sql(s"insert into t values($outOfRangeValue2)")
+        }.getCause.getMessage
+        assert(msg.contains(s"Casting $outOfRangeValue2 to byte causes 
overflow"))
+      }
+    }
+  }
+
+  test("Throw exceptions on inserting out-of-range short value with ANSI 
casting policy") {
+    withSQLConf(
+      SQLConf.STORE_ASSIGNMENT_POLICY.key -> 
SQLConf.StoreAssignmentPolicy.ANSI.toString) {
+      withTable("t") {
+        sql("create table t(b short) using parquet")
 
 Review comment:
   This is end-to-end test, and I don't think we need to enumerate all the 
cases. just pick some typical ones, like long -> int, decimal -> long, long -> 
decimal.

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