apache/flink · error · RuntimeException
Row arity of record ({}) does not match this serializer's fi
Error message
Row arity of record ({}) does not match this serializer's field length ({}). What it means
RowSerializer.serializePositionBased() writes a position-based Row to a DataOutputView. Before serializing, it asserts record.getArity() == fieldSerializers.length. If the Row has more or fewer fields than the serializer expects, this RuntimeException is thrown with both values. Serialization requires an exact arity match because the binary format uses a fixed-length null bitmask sized to the serializer's field count.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java:286
public int getArity() {
return arity;
}
@Override
public void serialize(Row record, DataOutputView target) throws IOException {
final Set<String> fieldNames = record.getFieldNames(false);
if (fieldNames == null) {
serializePositionBased(record, target);
} else {
serializeNameBased(record, fieldNames, target);
}
}
private void serializePositionBased(Row record, DataOutputView target) throws IOException {
final int length = fieldSerializers.length;
if (record.getArity() != length) {
throw new RuntimeException(
"Row arity of record ("
+ record.getArity()
+ ") does not match this "
+ "serializer's field length ("
+ length
+ ").");
}
// write bitmask
fillMask(length, record, mask, supportsRowKind, rowKindOffset);
writeMask(mask, target);
// serialize non-null fields
for (int fieldPos = 0; fieldPos < length; fieldPos++) {
final Object o = record.getField(fieldPos);
if (o != null) {
fieldSerializers[fieldPos].serialize(o, target);
}View on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure every Row serialized has arity == fieldSerializers.length.
- Align the TypeInformation/RowSerializer arity with the upstream operator's output schema.
- Validate arity in a MapFunction before the data reaches the serializer/network layer.
- After schema changes, reset state or implement migration.
Example fix
// before — Row arity 3, serializer expects 2
RowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer});
ser.serialize(Row.of(1, "a", 42), output); // arity 3 ≠ 2 → exception
// after — serializer arity matches data
RowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer, intSer});
ser.serialize(Row.of(1, "a", 42), output); // OK Defensive patterns
Strategy: validation
Validate before calling
// Validate Row arity before serialization
public static void safeSerialize(RowSerializer ser, Row record, DataOutputView out)
throws IOException {
if (record.getArity() != ser.getArity()) {
throw new IllegalArgumentException(
"Row arity " + record.getArity()
+ " != serializer arity " + ser.getArity());
}
ser.serialize(record, out);
} Try / catch
try {
serializer.serialize(record, output);
} catch (RuntimeException e) {
if (e.getMessage().contains("Row arity of record")) {
log.error("Cannot serialize: Row arity {} != expected {}",
record.getArity(), serializer.getArity());
}
throw e;
} Prevention
- Validate Row.getArity() == serializer.getArity() before every serialize call.
- Keep Row schema and serializer schema in sync — update both together.
- Add arity validation at source connectors.
- Reset state after schema changes.
When it happens
Trigger: RowSerializer.serialize(Row, DataOutputView) is called during network shuffle, checkpointing, or state backend write, and the Row's arity differs from the serializer's configured field count.
Common situations: An upstream operator changed the Row schema (added/removed a column) but the downstream serializer was not updated; two streams with different Row arities were unioned and fed into one operator; state restore from a savepoint with an older Row schema; a source connector emits Rows with the wrong number of fields.
Related errors
- Row arity of from ({}) does not match this serializer's fiel
- Row arity of reuse ({}) or from ({}) is incompatible with th
- Serializer does not support named field positions.
- Row arity of reuse ({}) does not match this serializer's fie
- Field at index %s must be of type byte[], but was %s
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a43509fd87489d30.
Report an issue: GitHub.