{"record":{"id":"3208db0c9bed1519","repo":"prestodb/presto","slug":"datatype-mismatch-3208db","errorCode":"DATATYPE_MISMATCH","errorMessage":"Mismatched types: %s vs %s","messagePattern":"Mismatched types: (.+?) vs (.+?)","errorType":"error_code","errorClass":"DataTypeMismatchException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/predicate/EquatableValueSet.java","lineNumber":293,"sourceCode":"    }\n\n    private static <T> Set<T> union(Set<T> set1, Set<T> set2)\n    {\n        return Stream.concat(set1.stream(), set2.stream())\n                .collect(toLinkedSet());\n    }\n\n    private static <T> Set<T> subtract(Set<T> set1, Set<T> set2)\n    {\n        return set1.stream()\n                .filter(value -> !set2.contains(value))\n                .collect(toLinkedSet());\n    }\n\n    private EquatableValueSet checkCompatibility(ValueSet other)\n    {\n        if (!getType().equals(other.getType())) {\n            throw new DataTypeMismatchException(String.format(\"Mismatched types: %s vs %s\", getType(), other.getType()));\n        }\n        if (!(other instanceof EquatableValueSet)) {\n            throw new IllegalStateException(String.format(\"ValueSet is not a EquatableValueSet: %s\", other.getClass()));\n        }\n        return (EquatableValueSet) other;\n    }\n\n    @Override\n    public int hashCode()\n    {\n        return Objects.hash(type, whiteList, entries);\n    }\n\n    @Override\n    public boolean equals(Object obj)\n    {\n        if (this == obj) {\n            return true;","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/predicate/EquatableValueSet.java#L275-L311","documentation":"EquatableValueSet.checkCompatibility requires that set operations are performed against another ValueSet of the same Presto Type and the same EquatableValueSet implementation; a Type mismatch throws DataTypeMismatchException, and a wrong implementation throws IllegalStateException (separate message).","triggerScenarios":"Calling union/intersect/overlaps/contains via otherValueSet with a ValueSet of a different Type, e.g. combining a VARCHAR EquatableValueSet with an INTEGER one.","commonSituations":"Merging discrete value sets from different columns or mismatched partition key types; predicate translation bugs in connectors; caching ValueSets keyed only by column name after a type change.","solutions":["Ensure both sets have equal Type before combining; coerce one side if needed","Build both sets via ValueSet.of(type, ...) with identical Type instances","Key any ValueSet/Domain caches by (column, type) not just column","Pre-check with setA.getType().equals(setB.getType()) and handle mismatch explicitly"],"exampleFix":"// before\nValueSet merged = varcharSet.union(intSet); // throws\n// after\nif (varcharSet.getType().equals(intSet.getType())) {\n    ValueSet merged = varcharSet.union(intSet);\n}","handlingStrategy":"validation","validationCode":"if (!a.getType().equals(b.getType())) {\n    throw new IllegalArgumentException(\"ValueSet type mismatch: \" + a.getType() + \" vs \" + b.getType());\n}\nValueSet merged = a.union(b);","typeGuard":null,"tryCatchPattern":"try { return a.union(b); } catch (DataTypeMismatchException e) { /* treat as incompatible predicates; widen to none/all */ }","preventionTips":["Construct ValueSets with the exact same Type instance per column","Include type in cache keys for stored predicates","Coerce before combining rather than relying on runtime checks"],"tags":["valueset","datatype-mismatch","predicate"],"backgroundTag":"datatype-mismatch","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}