{"record":{"id":"be3bafe8e1dccf6c","repo":"apache/flink","slug":"expected-two-fields-for-the-map-key-value-but-g","errorCode":null,"errorMessage":"Expected two fields for the map (key/value), but got: {}","messagePattern":"Expected two fields for the map \\(key/value\\), but got: (.+?)","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/protobuf/PatchedProtoWriteSupport.java","lineNumber":432,"sourceCode":"                                @Override\n                                public Optional<GroupType> visit(\n                                        LogicalTypeAnnotation.MapLogicalTypeAnnotation\n                                                mapLogicalType) {\n                                    return ofNullable(\n                                            type.asGroupType()\n                                                    .getType(\"key_value\")\n                                                    .asGroupType()\n                                                    .getType(\"value\")\n                                                    .asGroupType());\n                                }\n                            })\n                    .orElse(type.asGroupType());\n        }\n\n        private MapWriter createMapWriter(FieldDescriptor fieldDescriptor, Type type) {\n            List<FieldDescriptor> fields = fieldDescriptor.getMessageType().getFields();\n            if (fields.size() != 2) {\n                throw new UnsupportedOperationException(\n                        \"Expected two fields for the map (key/value), but got: \" + fields);\n            }\n\n            // KeyFieldWriter\n            FieldDescriptor keyProtoField = fields.get(0);\n            FieldWriter keyWriter = createWriter(keyProtoField, type);\n            keyWriter.setFieldName(keyProtoField.getName());\n            keyWriter.setIndex(0);\n\n            // ValueFieldWriter\n            FieldDescriptor valueProtoField = fields.get(1);\n            FieldWriter valueWriter = createWriter(valueProtoField, type);\n            valueWriter.setFieldName(valueProtoField.getName());\n            valueWriter.setIndex(1);\n\n            return new MapWriter(keyWriter, valueWriter);\n        }\n","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/protobuf/PatchedProtoWriteSupport.java#L414-L450","documentation":"When building a writer for a protobuf map field, the nested message type must have exactly two fields (key and value) per protobuf's map encoding. Any other field count throws UnsupportedOperationException from createMapWriter.","triggerScenarios":"A .proto map field whose entry message somehow has != 2 fields - typically hand-constructed Descriptors, proto schema manipulation, or a map-like repeated group message passed where a true map is expected.","commonSituations":"Custom Descriptor construction, dynamic descriptors built at runtime, or protobuf editions/features producing unexpected map entry shapes.","solutions":["Define the field as a proper proto map: map<K,V> field = N; so the compiler generates the 2-field MapEntry","If using a hand-built Descriptor for a map-like structure, ensure the entry message has exactly key and value fields","For repeated key-value groups that are not maps, use repeated message instead of map semantics"],"exampleFix":"// before (hand-built descriptor entry with 3 fields)\n// message BadEntry { string key = 1; string value = 2; string extra = 3; }\n\n// after\n// message GoodEntry { string key = 1; string value = 2; }\n// or in proto: map<string, string> entries = 1;","handlingStrategy":"validation","validationCode":"FieldDescriptor fd = ...;\nif (fd.isMapField() && fd.getMessageType().getFields().size() != 2) { throw new IllegalArgumentException(\"map entry must have exactly key+value: \" + fd.getFullName()); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use compiler-generated map fields (map<K,V>) rather than hand-built entry descriptors","Validate hand-constructed Descriptors before handing them to the parquet writer","Add a schema smoke-test that writes one sample message per top-level type in CI"],"tags":["parquet","protobuf","map","schema"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}