fanyue-xia commented on code in PR #49590:
URL: https://github.com/apache/spark/pull/49590#discussion_r1933068669
##########
sql/core/src/main/scala/org/apache/spark/sql/avro/AvroSerializer.scala:
##########
@@ -282,11 +284,21 @@ private[sql] class AvroSerializer(
}.toArray.unzip
val numFields = catalystStruct.length
+ val avroFields = avroStruct.getFields()
+ val isSchemaNullable = avroFields.asScala.map(_.schema().isNullable)
row: InternalRow =>
val result = new Record(avroStruct)
var i = 0
while (i < numFields) {
if (row.isNullAt(i)) {
+ if (!isSchemaNullable(i)) {
+ throw new SparkRuntimeException(
+ errorClass = "AVRO_CANNOT_WRITE_NULL_FIELD",
+ messageParameters = Map(
+ "name" -> toSQLId(avroFields.get(i).name),
+ "dataType" -> toSQLType(SchemaConverters.toSqlType(
Review Comment:
Updated
--
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]