{"record":{"id":"0cc05f70e286ffb1","repo":"apache/iceberg","slug":"fail-to-serialize-at-field-s","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/v1.20/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/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java#L315-L351","documentation":"createRowConverter builds a converter that serializes each RowData field into a GenericRecord. Any Throwable thrown while converting an individual field (type mismatch with the Avro schema, NPE from mismatched field order, unsupported nested type, etc.) is rethrown as a RuntimeException annotated with the field name via String.format(\"Fail to serialize at field: %s.\").","triggerScenarios":"RowDataToAvroConverters row conversion where fieldConverters[i].convert(...) throws — e.g. field value's LogicalType doesn't match the Avro field schema, DecimalData/stringData conversion failure, or the inner converter throws (including error 1260's union rejection) for the field named in the message.","commonSituations":"Row schema and Avro schema drifted out of sync after a schema change; field ordering mismatch causing a value to be converted against the wrong Avro field; a single bad row (wrong precision timestamp, malformed decimal) failing a whole Flink job writing Avro files.","solutions":["Read the cause (`t`) chained in the RuntimeException — it names the real conversion failure; fix that root cause.","Verify the Flink RowType and the target Avro schema have identical field names, order, and types.","Recreate the converter after any schema evolution — stale converters built for the old schema fail on new rows.","Locate and fix or filter the offending data row(s); the field name in the message narrows the column to check.","If caused by nested converters, apply the fix at the nested level (e.g. correct timestamp precision or union shape)."],"exampleFix":"// before\nRecord record = ...; // built with old schema (3 fields)\nrowConverter.convert(recordSchema /* 4 fields */, row); // fails at 4th field\n// after\nRowType rowType = (RowType) tableSchema.toPhysicalRowDataType().getLogicalType();\nRowDataToAvroConverter converter = RowDataToAvroConverters.createConverter(rowType, false);\nconverter.convert(updatedRecordSchema, row); // schemas aligned","handlingStrategy":"try-catch","validationCode":"if (row.getArity() != schema.getFields().size()) {\n  throw new IllegalStateException(\"Row arity \" + row.getArity() + \" != schema fields \" + schema.getFields().size());\n}","typeGuard":null,"tryCatchPattern":"try {\n  GenericRecord rec = rowConverter.convert(recordSchema, row);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Fail to serialize at field:\")) {\n    LOG.error(\"Field serialization failed: {} cause: {}\", e.getMessage(), e.getCause(), e);\n    // route row to DLQ or fix schema alignment\n  } else throw e;\n}","preventionTips":["Keep the Flink RowType and Avro record schema generated from the same source of truth.","Rebuild converters whenever the schema changes; never cache across schema versions.","Always inspect getCause() — this exception is only a wrapper."],"tags":["avro","flink","serialization","wrapper-exception"],"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-14T16:17:12.679Z"}