{"record":{"id":"c4bef7ff14c9a9dc","repo":"apache/iceberg","slug":"fail-to-serialize-at-field-s-c4bef7","errorCode":null,"errorMessage":"Fail to serialize at field: %s.","messagePattern":"Fail to serialize at field: (.+?)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java","lineNumber":333,"sourceCode":"    final int length = rowType.getFieldCount();\n\n    return new RowDataToAvroConverter() {\n      private static final long serialVersionUID = 1L;\n\n      @Override\n      public Object convert(Schema schema, Object object) {\n        final RowData row = (RowData) object;\n        final List<Schema.Field> fields = schema.getFields();\n        final GenericRecord record = new GenericData.Record(schema);\n        for (int i = 0; i < length; ++i) {\n          final Schema.Field schemaField = fields.get(i);\n          try {\n            Object avroObject =\n                fieldConverters[i].convert(\n                    schemaField.schema(), fieldGetters[i].getFieldOrNull(row));\n            record.put(i, avroObject);\n          } catch (Throwable t) {\n            throw new RuntimeException(\n                String.format(\"Fail to serialize at field: %s.\", schemaField.name()), t);\n          }\n        }\n        return record;\n      }\n    };\n  }\n\n  private static RowDataToAvroConverter createArrayConverter(\n      ArrayType arrayType, boolean legacyTimestampMapping) {\n    LogicalType elementType = arrayType.getElementType();\n    final ArrayData.ElementGetter elementGetter = ArrayData.createElementGetter(elementType);\n    final RowDataToAvroConverter elementConverter =\n        createConverter(arrayType.getElementType(), legacyTimestampMapping);\n\n    return new RowDataToAvroConverter() {\n      private static final long serialVersionUID = 1L;\n","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java#L315-L351","documentation":"This error wraps any Throwable thrown while converting a single Flink RowData field to its Avro representation during record serialization. The wrapper preserves the original cause as the 'cause' and identifies the failing field by its name, since the underlying conversion failure could be a null mismatch, an unsupported value, or an internal converter error. It exists so a serialization failure in a large row can be attributed to a specific field.","triggerScenarios":"RowDataToAvroConverters.convert() creates a value getter/converter pair per field; calling the returned AvroValueConverter or writing records via an Avro writer when any field converter throws (e.g. unexpected row type, null in a non-nullable field, wrong internal data structure).","commonSituations":"Writing Flink RowData to Avro files or Kafka topics where one column's runtime value does not match the declared schema (e.g. a timestamp with wrong precision, a map with unexpected key type, or a Decimal with wrong scale after a schema change).","solutions":["Read the 'cause' of the RuntimeException to find the real conversion failure.","Check the named field's data type and the actual runtime values against the Avro schema.","Ensure the RowData was produced with the same schema used to build the converters (schema evolution drift is a common cause).","For nullable Avro fields, verify the field getter returns null correctly rather than an incompatible default."],"exampleFix":"// before\n// failing: field 'ts' is TIMESTAMP(6) but schema expects timestampMillis\n// after\n// cast/adjust the column before writing, e.g. in Flink SQL:\n// SELECT CAST(ts AS TIMESTAMP(3)) AS ts, ... FROM source","handlingStrategy":"try-catch","validationCode":"row.getField(i) != null || avroSchema.getFields().get(i).schema().getType() == Schema.Type.NULL; // validate nullability per field before writing","typeGuard":null,"tryCatchPattern":"try { writer.write(record); } catch (RuntimeException e) { Throwable cause = e.getCause(); LOG.error(\"Avro serialization failed at field: {}\", e.getMessage(), cause); throw e; }","preventionTips":["Keep the RowData schema and the Avro schema in sync; regenerate converters on schema change.","Check getCause() first — this error is only a wrapper.","Unit-test serialization with representative rows including nulls.","Log field name and value type on failure before rethrowing."],"tags":["flink","avro","serialization"],"backgroundTag":"json-serialization-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}