steven-aerts commented on code in PR #36506: URL: https://github.com/apache/spark/pull/36506#discussion_r1005253894
########## connector/avro/src/main/scala/org/apache/spark/sql/avro/AvroSerializer.scala: ########## @@ -312,14 +368,11 @@ private[sql] class AvroSerializer( */ private def resolveAvroType(avroType: Schema): (Boolean, Schema) = { if (avroType.getType == Type.UNION) { - val fields = avroType.getTypes.asScala - val actualType = fields.filter(_.getType != Type.NULL) - if (fields.length != 2 || actualType.length != 1) { - throw new UnsupportedAvroTypeException( - s"Unsupported Avro UNION type $avroType: Only UNION of a null type and a non-null " + - "type is supported") + nonNullUnionBranches(avroType) match { + case Seq() => (true, Schema.create(Type.NULL)) + case Seq(singleType) => (true, singleType) + case _ => (false, avroType) Review Comment: I think this is exactly what we are doing here, by using the output of `nonNullUnionBranches`. We make however an exception of `["null"]`. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org