{"record":{"id":"410817d75749ed4e","repo":"apache/flink","slug":"avro-format-doesn-t-support-non-string-as-key-type","errorCode":null,"errorMessage":"Avro format doesn't support non-string as key type of map. The key type is: %s","messagePattern":"Avro format doesn't support non-string as key type of map\\. The key type is: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java","lineNumber":598,"sourceCode":"                throw new UnsupportedOperationException(\n                        \"Unsupported to derive Schema for type: \" + logicalType);\n        }\n    }\n\n    public static LogicalType extractValueTypeToAvroMap(LogicalType type) {\n        LogicalType keyType;\n        LogicalType valueType;\n        if (type instanceof MapType) {\n            MapType mapType = (MapType) type;\n            keyType = mapType.getKeyType();\n            valueType = mapType.getValueType();\n        } else {\n            MultisetType multisetType = (MultisetType) type;\n            keyType = multisetType.getElementType();\n            valueType = new IntType();\n        }\n        if (!keyType.is(LogicalTypeFamily.CHARACTER_STRING)) {\n            throw new UnsupportedOperationException(\n                    \"Avro format doesn't support non-string as key type of map. \"\n                            + \"The key type is: \"\n                            + keyType.asSummaryString());\n        }\n        return valueType;\n    }\n\n    /** Returns schema with nullable true. */\n    private static Schema nullableSchema(Schema schema) {\n        return schema.isNullable()\n                ? schema\n                : Schema.createUnion(SchemaBuilder.builder().nullType(), schema);\n    }\n}\n","sourceCodeStart":580,"sourceCodeEnd":613,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java#L580-L613","documentation":"UnsupportedOperationException from extractValueTypeToAvroMap when a Flink MAP's key type (or MULTISET element type) is not in the CHARACTER_STRING family. Avro map keys are always strings, so maps keyed by INT, BIGINT, etc. cannot be converted to an Avro schema.","triggerScenarios":"convertToSchema on MAP<INT, ...> or MAP<BIGINT, ...>; MULTISET<INT>; an avro-format table declaring a map column with a non-string key.","commonSituations":"Schemas with id-to-value maps (e.g. MAP<BIGINT, STRING>) coming from JSON/Kafka sources where non-string keys are legal.","solutions":["Change the key type to VARCHAR/STRING (convert keys to strings upstream or via a computed column).","Model the mapping as ARRAY<ROW<key ..., value ...>> which supports any key type."],"exampleFix":"-- before\nid_to_name MAP<BIGINT, STRING>,\n\n-- after\nid_to_name MAP<STRING, STRING>,\n-- or\nid_to_name ARRAY<ROW<id BIGINT, name STRING>>,\n-- or (multiset is string-family)\nid_counts MULTISET<STRING>,","handlingStrategy":"validation","validationCode":"import org.apache.flink.table.types.logical.MapType;\nimport org.apache.flink.table.types.logical.LogicalTypeFamily;\n\nboolean avroConvertible(MapType m) {\n    return m.getKeyType().is(LogicalTypeFamily.CHARACTER_STRING);\n}","typeGuard":"boolean hasStringKeys(MapType m) { return m.getKeyType().is(LogicalTypeFamily.CHARACTER_STRING); }","tryCatchPattern":null,"preventionTips":["Model non-string keyed mappings as ARRAY<ROW<k ..., v ...>> in avro tables.","Stringify map keys at the source or in a computed column before the sink."],"tags":["avro","map-key","flink","schema-conversion","type-mapping"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}