{"record":{"id":"1709b06026a7d6a0","repo":"prestodb/presto","slug":"expected-varchartype-but-got-type-getclass-getn","errorCode":null,"errorMessage":"Expected VarcharType but got {type.getClass().getName()}","messagePattern":"Expected VarcharType but got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java","lineNumber":490,"sourceCode":"    }\n\n    public void assignBlockFromVarBinaryVector(VarBinaryVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                byte[] value = vector.get(i);\n                type.writeSlice(builder, Slices.wrappedBuffer(value));\n            }\n        }\n    }\n\n    public void assignBlockFromVarCharVector(VarCharVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {\n        if (!(type instanceof VarcharType)) {\n            throw new IllegalArgumentException(\"Expected VarcharType but got \" + type.getClass().getName());\n        }\n\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                // Directly create a Slice from the raw byte array\n                byte[] rawBytes = vector.get(i);\n                Slice slice = Slices.wrappedBuffer(rawBytes);\n                // Write the Slice directly to the builder\n                type.writeSlice(builder, slice);\n            }\n        }\n    }\n\n    public void assignBlockFromDateDayVector(DateDayVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java#L472-L508","documentation":"assignBlockFromVarCharVector expects the paired Presto Type to be VarcharType because it decodes Arrow UTF-8 bytes into Presto varchar slices. If type is not a VarcharType it throws IllegalArgumentException('Expected VarcharType but got <class>').","triggerScenarios":"assignBlockFromValueVector dispatches a VarCharVector while the mapped Type resolved to something else (e.g. BIGINT, JSON, or a char type) via an incorrect type mapping.","commonSituations":"String columns mapped to a non-varchar Presto type in the catalog; metadata drift after upstream schema changes; hand-written conversion code passing the wrong Type object.","solutions":["Fix the mapping so Arrow string columns map to Presto VarcharType","Refresh or correct the connector schema metadata","Cast the column to string on the producer side if a non-varchar type was intended","Validate the Type before calling assignBlockFromValueVector"],"exampleFix":"// before\nType type = JSON; // mismatch for VarCharVector\n// after\nType type = VarcharType.createVarcharType();","handlingStrategy":"validation","validationCode":"checkArgument(type instanceof VarcharType,\n    \"Column %s is VarCharVector but declared type is %s\", vector.getName(), type.getDisplayName());","typeGuard":"boolean isCompatiblePrestoType(ValueVector v, Type t) {\n    if (v instanceof VarCharVector) {\n        return t instanceof VarcharType;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    blockBuilder.assignBlockFromVarCharVector(varCharVector, type, builder, 0, n);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Expected VarcharType\")) {\n        throw new SchemaMismatchException(vector.getName(), type, \"VARCHAR\", e);\n    }\n    throw e;\n}","preventionTips":["Map Arrow string columns to Presto VARCHAR; use VARCHAR for JSON-ish data too","Regenerate table metadata after upstream schema changes","Derive the Type from the Arrow field rather than an external schema registry that may lag"],"tags":["arrow","java","type-mismatch","varchar","illegal-argument"],"backgroundTag":"arrow-presto-type-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"}