{"record":{"id":"309d890f9533cba7","repo":"apache/flink","slug":"typeinformation-and-typeinformation2-are-not-c","errorCode":null,"errorMessage":"{typeInformation} and {typeInformation2} are not compatible","messagePattern":"(.+?) and (.+?) are not compatible","errorType":"exception","errorClass":"IncompatibleKeysException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java","lineNumber":70,"sourceCode":"    public abstract <E> void validateCustomPartitioner(\n            Partitioner<E> partitioner, TypeInformation<E> typeInfo);\n\n    public boolean isEmpty() {\n        return getNumberOfKeyFields() == 0;\n    }\n\n    /** Check if two sets of keys are compatible to each other (matching types, key counts) */\n    public boolean areCompatible(Keys<?> other) throws IncompatibleKeysException {\n\n        TypeInformation<?>[] thisKeyFieldTypes = this.getKeyFieldTypes();\n        TypeInformation<?>[] otherKeyFieldTypes = other.getKeyFieldTypes();\n\n        if (thisKeyFieldTypes.length != otherKeyFieldTypes.length) {\n            throw new IncompatibleKeysException(IncompatibleKeysException.SIZE_MISMATCH_MESSAGE);\n        } else {\n            for (int i = 0; i < thisKeyFieldTypes.length; i++) {\n                if (!thisKeyFieldTypes[i].equals(otherKeyFieldTypes[i])) {\n                    throw new IncompatibleKeysException(\n                            thisKeyFieldTypes[i], otherKeyFieldTypes[i]);\n                }\n            }\n        }\n        return true;\n    }\n\n    // --------------------------------------------------------------------------------------------\n    //  Specializations for expression-based / extractor-based grouping\n    // --------------------------------------------------------------------------------------------\n\n    public static class SelectorFunctionKeys<T, K> extends Keys<T> {\n\n        private final KeySelector<T, K> keyExtractor;\n        private final TypeInformation<T> inputType;\n        private final TypeInformation<K> keyType;\n        private final List<FlatFieldDescriptor> keyFields;\n        private final TypeInformation<?>[] originalKeyTypes;","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java#L52-L88","documentation":"Thrown by Keys.areCompatible() as IncompatibleKeysException(typeInformation, typeInformation2) when two key specifications have the same arity but at some position the key field types differ (e.g. BasicTypeInfo.STRING vs BasicTypeInfo.INT). The runtime pairs key fields positionally and requires exact type equality for comparator selection.","triggerScenarios":"Calling .where(0).equalTo(0) on two DataSets where field 0 is a String on one side and an Integer on the other; joining a Long key with an Integer key; mismatched POJO field types used as keys.","commonSituations":"Joining datasets whose key columns have compatible-but-not-equal types (Long vs Integer, String vs a custom type); schema drift where one side's key column type changed; using a KeySelector that returns a different primitive wrapper on each side.","solutions":["Align the key types exactly on both sides (e.g. cast or map one side so both keys are the same TypeInformation).","If types are logically compatible, project one side through a map to the other's key type before joining.","Inspect the two TypeInformation values named in the message to identify the divergent field position."],"exampleFix":"// before (a.key is String, b.key is Long)\ndsA.join(dsB).where(0).equalTo(0);\n// after — project a.key to Long\ndsA.map(t -> Tuple2.of(Long.parseLong(t.f0), t.f1)).returns(Types.TUPLE(Types.LONG, Types.STRING))\n   .join(dsB).where(0).equalTo(0);","handlingStrategy":"validation","validationCode":"TypeInformation<?>[] lt = leftKeys.getKeyFieldTypes();\nTypeInformation<?>[] rt = rightKeys.getKeyFieldTypes();\nfor (int i = 0; i < lt.length; i++) {\n    if (!lt[i].equals(rt[i])) {\n        throw new IllegalStateException(\"Key type mismatch at position \" + i + \": \" + lt[i] + \" vs \" + rt[i]);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    a.join(b).where(0).equalTo(0);\n} catch (Exception e) {\n    if (e.getCause() instanceof Keys.IncompatibleKeysException) { /* project key types to match */ }\n    throw e;\n}","preventionTips":["Make both join key columns the same TypeInformation (e.g. both Types.LONG).","Project one side through a map when types are only logically compatible.","Add a unit test asserting key type equality before executing the join."],"tags":["flink-core","keys","join","type-compatibility","dataset-api"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}