{"record":{"id":"d23183c69584326c","repo":"apache/flink","slug":"row-arity-of-from-does-not-match-this-seriali","errorCode":null,"errorMessage":"Row arity of from ({}) does not match this serializer's field length ({}).","messagePattern":"Row arity of from \\((.+?)\\) does not match this serializer's field length \\((.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java","lineNumber":148,"sourceCode":"    public Row createInstance() {\n        return RowUtils.createRowWithNamedPositions(\n                RowKind.INSERT, new Object[fieldSerializers.length], positionByName);\n    }\n\n    @Override\n    public Row copy(Row from) {\n        final Set<String> fieldNames = from.getFieldNames(false);\n        if (fieldNames == null) {\n            return copyPositionBased(from);\n        } else {\n            return copyNameBased(from, fieldNames);\n        }\n    }\n\n    private Row copyPositionBased(Row from) {\n        final int length = fieldSerializers.length;\n        if (from.getArity() != length) {\n            throw new RuntimeException(\n                    \"Row arity of from (\"\n                            + from.getArity()\n                            + \") does not match \"\n                            + \"this serializer's field length (\"\n                            + length\n                            + \").\");\n        }\n        final Object[] fieldByPosition = new Object[length];\n        for (int i = 0; i < length; i++) {\n            final Object fromField = from.getField(i);\n            if (fromField != null) {\n                final Object copy = fieldSerializers[i].copy(fromField);\n                fieldByPosition[i] = copy;\n            }\n        }\n        return RowUtils.createRowWithNamedPositions(\n                from.getKind(), fieldByPosition, positionByName);\n    }","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java#L130-L166","documentation":"RowSerializer.copyPositionBased() copies a position-based Row (one without named fields). Before copying each field, it asserts that the source Row's arity equals the serializer's configured field count (fieldSerializers.length). If they differ, this RuntimeException is thrown with both numbers in the message. The serializer can only copy Rows whose arity exactly matches its schema.","triggerScenarios":"RowSerializer.copy(Row) is called (e.g., during state snapshot, shuffle, or operator chaining) with a Row whose getArity() does not equal the number of field serializers the RowSerializer was constructed with.","commonSituations":"The upstream operator emits a Row with a different number of fields than the TypeInformation/RowSerializer expects; a schema change (adding/removing a column) was made to one operator but not downstream; restoring state from a savepoint whose Row schema has a different arity; a union of two streams with different Row arities feeding into the same operator.","solutions":["Ensure every Row passed to the serializer has arity == the serializer's fieldSerializers.length.","If the schema changed, update all downstream operators and serializers to the new arity.","If restoring from a savepoint with a different arity, implement state migration or start fresh.","Validate Row arity in an upstream MapFunction before it reaches the serializer."],"exampleFix":"// before — Row arity 3 fed to a serializer expecting arity 2\nRowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer}); // length 2\nser.copy(Row.of(1, \"a\", 42)); // arity 3 ≠ 2 → exception\n\n// after — match arity\nRowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer, intSer}); // length 3\nser.copy(Row.of(1, \"a\", 42)); // arity 3 == 3 → OK","handlingStrategy":"validation","validationCode":"// Validate Row arity before copying\npublic static Row safeCopy(RowSerializer ser, Row from) {\n    if (from.getArity() != ser.getArity()) {\n        throw new IllegalArgumentException(\n            \"Row arity \" + from.getArity()\n            + \" != serializer arity \" + ser.getArity());\n    }\n    return ser.copy(from);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Row copy = serializer.copy(from);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Row arity of from\")) {\n        log.error(\"Arity mismatch: expected {}, got {}\",\n            serializer.getArity(), from.getArity());\n    }\n    throw e;\n}","preventionTips":["Validate Row.getArity() == serializer field count before copy/serialize.","Keep Row schemas consistent across all pipeline stages.","After schema changes, reset state or implement migration.","Add arity checks at source connectors."],"tags":["row","serializer","arity-mismatch","schema","position-based"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}