Github user dbtsai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21847#discussion_r206356838
  
    --- Diff: 
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroSerializer.scala ---
    @@ -146,9 +159,13 @@ class AvroSerializer(rootCatalystType: DataType, 
rootAvroType: Schema, nullable:
       private def newStructConverter(
           catalystStruct: StructType, avroStruct: Schema): InternalRow => 
Record = {
         val avroFields = avroStruct.getFields
    -    assert(avroFields.size() == catalystStruct.length)
    +    if (avroFields.size != catalystStruct.length) {
    +      throw new IncompatibleSchemaException(
    +        s"Field list length of ${catalystStruct} does not correspond to 
length of ${avroStruct}")
    +    }
         val fieldConverters = catalystStruct.zip(avroFields.asScala).map {
    -      case (f1, f2) => newConverter(f1.dataType, 
resolveNullableType(f2.schema(), f1.nullable))
    +      case (f1, f2) =>
    +        newConverter(f1.dataType, resolveUnionType(f2.schema(), 
f1.dataType, f1.nullable))
    --- End diff --
    
    ```scala
    val fieldConverters = catalystStruct.zip(avroFields.asScala).map { case 
(f1, f2) =>
      newConverter(f1.dataType, resolveUnionType(f2.schema(), f1.dataType, 
f1.nullable))
    }
    
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to