apache/flink · error · RuntimeException
Could not serialize row '%s'.
Error message
Could not serialize row '%s'.
What it means
Outer catch in CsvRowDataSerializationSchema.serialize(): any Throwable thrown while converting the RowData into the CSV ObjectNode or writing it with Jackson is re-thrown as RuntimeException("Could not serialize row '%s'."). The failing row is included and the real cause (usually a converter type error) is attached.
Source
Thrown at flink-formats/flink-csv/src/main/java/org/apache/flink/formats/csv/CsvRowDataSerializationSchema.java:183
JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES, false);
return csvMapper;
});
}
}
@Override
public byte[] serialize(RowData row) {
if (root == null) {
root = csvMapper.createObjectNode();
converterContext =
new RowDataToCsvConverters.RowDataToCsvConverter
.RowDataToCsvFormatConverterContext(csvMapper, root);
}
try {
runtimeConverter.convert(row, converterContext);
return objectWriter.writeValueAsBytes(root);
} catch (Throwable t) {
throw new RuntimeException(String.format("Could not serialize row '%s'.", row), t);
}
}
@Override
public boolean equals(Object o) {
if (o == null || o.getClass() != this.getClass()) {
return false;
}
if (this == o) {
return true;
}
final CsvRowDataSerializationSchema that = (CsvRowDataSerializationSchema) o;
final CsvSchema otherSchema = that.csvSchema;
return rowType.equals(that.rowType)
&& csvSchema.getColumnSeparator() == otherSchema.getColumnSeparator()
&& Arrays.equals(csvSchema.getLineSeparator(), otherSchema.getLineSeparator())
&& csvSchemaView on GitHub (pinned to 2f3c205e92)
Solutions
- Read the chained cause to identify which field/converter failed; the row dump shows the offending values.
- Align the emitting side's RowType with the sink table schema exactly (types and nullability).
- Test serialization in a unit test: new CsvRowDataSerializationSchema(rowType, options).serialize(row) to reproduce cheaply.
- If the cause is an unsupported type, project/cast the column to a CSV-supported type (e.g. MAP to STRING) before the sink.
Defensive patterns
Strategy: try-catch
Validate before calling
// Reproduce serialization cheaply before deploying:
SerializationSchema<RowData> ser = new CsvRowDataSerializationSchema(rowType, config);
for (RowData sample : representativeRows) { ser.serialize(sample); } // throws here, not in prod Try / catch
catch (RuntimeException e) { send the row (rendered in e.getMessage()) to a dead-letter sink; rethrow only for systemic causes (schema/registry) } Prevention
- Unit-test the serializer with nulls, extremes, and every RowKind
- Keep emitting RowType identical to the sink DDL
- Cast complex fields to STRING before CSV sinks
When it happens
Trigger: RowData values incompatible with the declared CSV schema: wrong physical type in a GenericRowData, unsupported nested types, nulls rendered into positions the CsvSchema cannot format, or date/time strings that Jackson's CSV generator rejects.
Common situations: Custom sources emitting GenericRowData with mismatched internal representations (e.g. byte[] where STRING expected); schema drift between the producing job and the CSV sink DDL; timestamps with precision the CSV schema cannot render.
Related errors
- Can't deserialize Debezium Avro message.
- Could not serialize row '%s'.
- Could not serialize row '%s'.
- Could not serialize row '%s'.
- Cannot deserialize and unwrap accumulators properly.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/e101c6de051ea206.
Report an issue: GitHub.