zeruibao commented on code in PR #41052:
URL: https://github.com/apache/spark/pull/41052#discussion_r1189110112


##########
connector/avro/src/test/scala/org/apache/spark/sql/avro/AvroSuite.scala:
##########
@@ -639,6 +640,39 @@ abstract class AvroSuite
     }
   }
 
+  test("SPARK-43380: Fix Avro data type conversion issues to avoid producing 
incorrect results") {
+    withTempPath { path =>
+      sql("SELECT 13.1234567890 a").write.format("avro").save(path.toString)
+      // With the flag disabled, we will throw an exception if there is a 
mismatch
+      val e = intercept[SparkException] {
+        spark.read.schema("a DECIMAL(4, 
3)").format("avro").load(path.toString).collect()
+      }
+      val confKey = 
SQLConf.LEGACY_AVRO_ALLOW_READING_WITH_INCOMPATIBLE_SCHEMA.key
+      ExceptionUtils.getRootCause(e) match {
+        case ex: IncompatibleSchemaException =>
+          assert(ex.getMessage.contains(confKey))
+        case other =>
+          fail(s"Received unexpected exception", other)
+      }
+      // The following used to work, so it should still work with the flag 
enabled
+      checkAnswer(
+        spark.read.schema("a DECIMAL(5, 
3)").format("avro").load(path.toString),
+        Row(new java.math.BigDecimal("13.123"))
+      )
+      withSQLConf(confKey -> "true") {

Review Comment:
   actually I have one above. But I can use `withSQLConf(confKey -> "false") {` 
explicitly to make it clear.



-- 
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: [email protected]

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