cloud-fan commented on a change in pull request #25581: [SPARK-28495][SQL]
Introduce ANSI store assignment policy for table insertion
URL: https://github.com/apache/spark/pull/25581#discussion_r317943392
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala
##########
@@ -582,6 +582,45 @@ class InsertSuite extends DataSourceTest with
SharedSparkSession {
}
}
+ test("Throw exception on unsafe cast with ANSI casting policy") {
+ withSQLConf(
+ SQLConf.USE_V1_SOURCE_WRITER_LIST.key -> "parquet",
+ SQLConf.STORE_ASSIGNMENT_POLICY.key ->
SQLConf.StoreAssignmentPolicy.ANSI.toString) {
+ withTable("t") {
+ sql("create table t(i int, d double) using parquet")
+ var msg = intercept[AnalysisException] {
+ sql("insert into t values('a', 'b')")
+ }.getMessage
+ assert(msg.contains("Cannot cast 'i': StringType to IntegerType") &&
+ msg.contains("Cannot cast 'd': StringType to DoubleType"))
+ msg = intercept[AnalysisException] {
+ sql("insert into t values(now(), now())")
+ }.getMessage
+ assert(msg.contains("Cannot cast 'i': TimestampType to IntegerType") &&
+ msg.contains("Cannot cast 'd': TimestampType to DoubleType"))
+ msg = intercept[AnalysisException] {
+ sql("insert into t values(true, false)")
+ }.getMessage
+ assert(msg.contains("Cannot cast 'i': BooleanType to IntegerType") &&
+ msg.contains("Cannot cast 'd': BooleanType to DoubleType"))
+ }
+ }
+ }
+
+ test("Allow on writing any numeric value to numeric type with ANSI policy") {
Review comment:
let's also test "write timestamp to date column"
----------------------------------------------------------------
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]