gengliangwang commented on code in PR #41052:
URL: https://github.com/apache/spark/pull/41052#discussion_r1187865028
##########
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") {
+ // With the flag enabled, we return a null silently, which isn't great
+ checkAnswer(
Review Comment:
We need test cases for the following code branches
```
case (INT, y: YearMonthIntervalType) if isNotExactType =>
throw incorrectTypeException(y)
case (LONG, dt: DayTimeIntervalType) if isNotExactType =>
throw incorrectTypeException(dt)
case (LONG, dt: TimestampType)
if preventReadingIncorrectType &&
realDataType.isInstanceOf[DayTimeIntervalType] =>
throw incorrectTypeException(dt)
case (LONG, dt: TimestampNTZType)
if preventReadingIncorrectType &&
realDataType.isInstanceOf[DayTimeIntervalType] =>
throw incorrectTypeException(dt)
```
##########
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:
Let's add tests for confKey as false
--
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]