xkrogen commented on a change in pull request #31490:
URL: https://github.com/apache/spark/pull/31490#discussion_r658893000



##########
File path: 
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroSerializer.scala
##########
@@ -240,29 +240,30 @@ private[sql] class AvroSerializer(
       catalystPath: Seq[String],
       avroPath: Seq[String]): InternalRow => Record = {
 
-    val avroPathStr = toFieldStr(avroPath)
-    if (avroStruct.getType != RECORD) {
-      throw new IncompatibleSchemaException(s"$avroPathStr was not a RECORD")
+    val avroSchemaHelper =
+      new AvroUtils.AvroSchemaHelper(avroStruct, catalystStruct, avroPath, 
positionalFieldMatch)
+
+    avroSchemaHelper.getCatalystFieldsWithoutMatch match {
+      case Seq() => // do nothing
+      case extraFields => throw new IncompatibleSchemaException(
+        s"Cannot find in Avro ${toFieldStr(avroPath)}: " + extraFields
+          .map(f => toFieldStr(catalystPath :+ f.name))
+          .mkString("[", ", ", "]"))
     }
-    val avroFields = avroStruct.getFields.asScala
-    if (avroFields.size != catalystStruct.length) {
-      throw new IncompatibleSchemaException(
-        s"Avro $avroPathStr schema length (${avroFields.size}) doesn't match " 
+
-        s"SQL ${toFieldStr(catalystPath)} schema length 
(${catalystStruct.length})")
+    avroSchemaHelper.getAvroFieldsWithoutMatch.toSeq match {

Review comment:
       Responding on the `AvroDeserializer` comment to keep discussion 
consolidated.




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