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


##########
connector/avro/src/main/scala/org/apache/spark/sql/avro/AvroDeserializer.scala:
##########
@@ -117,6 +118,24 @@ private[sql] class AvroDeserializer(
     val incompatibleMsg = errorPrefix +
         s"schema is incompatible (avroType = $avroType, sqlType = 
${catalystType.sql})"
 
+    val realDataType = SchemaConverters.toSqlType(avroType).dataType
+    val confKey = SQLConf.LEGACY_AVRO_ALLOW_READING_WITH_INCOMPATIBLE_SCHEMA
+    val preventReadingIncorrectType = !SQLConf.get.getConf(confKey)
+    def incorrectTypeException(provided: DataType): 
IncompatibleSchemaException = {

Review Comment:
   Let's move the error to `QueryCompilationErrors` and assign an error class 
to it.



##########
connector/avro/src/main/scala/org/apache/spark/sql/avro/AvroDeserializer.scala:
##########
@@ -117,6 +118,24 @@ private[sql] class AvroDeserializer(
     val incompatibleMsg = errorPrefix +
         s"schema is incompatible (avroType = $avroType, sqlType = 
${catalystType.sql})"
 
+    val realDataType = SchemaConverters.toSqlType(avroType).dataType
+    val confKey = SQLConf.LEGACY_AVRO_ALLOW_READING_WITH_INCOMPATIBLE_SCHEMA
+    val preventReadingIncorrectType = !SQLConf.get.getConf(confKey)
+    def incorrectTypeException(provided: DataType): 
IncompatibleSchemaException = {
+      new IncompatibleSchemaException(errorPrefix + "the original encoded data 
type is " +
+        s"${realDataType.catalogString}, however you're trying to read the 
field as " +
+        s"${provided.catalogString}, which would lead to an incorrect answer. 
To allow reading " +
+        s"this field, enable the SQL configuration: `${confKey.key}`.")
+    }
+
+    def lowerPrecisionException(provided: DataType): 
IncompatibleSchemaException = {

Review Comment:
   Let's move the error to `QueryCompilationErrors` and assign an error class 
to it.



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