{"record":{"id":"2857b37429255afc","repo":"prestodb/presto","slug":"mapping-length-s-is-not-equal-to-expected-lengt","errorCode":null,"errorMessage":"Mapping length '%s' is not equal to expected length '%s' for column '%s'","messagePattern":"Mapping length '(.+?)' is not equal to expected length '(.+?)' for column '(.+?)'","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/raw/RawRowEncoder.java","lineNumber":95,"sourceCode":"\n    private final List<ColumnMapping> columnMappings;\n    private final ByteBuffer buffer;\n\n    public RawRowEncoder(ConnectorSession session, List<EncoderColumnHandle> columnHandles)\n    {\n        super(session, columnHandles);\n\n        for (EncoderColumnHandle handle : this.columnHandles) {\n            checkArgument(isSupportedType(handle.getType()), \"Unsupported column type '%s' for column '%s'\", handle.getType().getDisplayName(), handle.getName());\n            checkArgument(handle.getFormatHint() == null, \"Unexpected format hint '%s' defined for column '%s'\", handle.getFormatHint(), handle.getName());\n        }\n\n        // parse column mappings from column handles\n        this.columnMappings = this.columnHandles.stream().map(ColumnMapping::new).collect(toImmutableList());\n\n        for (ColumnMapping mapping : this.columnMappings) {\n            if (mapping.getLength() != mapping.getFieldType().getSize() && !isVarcharType(mapping.getType())) {\n                throw new IndexOutOfBoundsException(format(\n                        \"Mapping length '%s' is not equal to expected length '%s' for column '%s'\",\n                        mapping.getLength(),\n                        mapping.getFieldType().getSize(),\n                        mapping.getName()));\n            }\n        }\n\n        // check that column mappings don't overlap and that there are no gaps\n        int position = 0;\n        for (ColumnMapping mapping : this.columnMappings) {\n            checkArgument(mapping.getStart() == position, format(\n                    \"Start mapping '%s' for column '%s' does not equal expected mapping '%s'\",\n                    mapping.getStart(),\n                    mapping.getName(),\n                    position));\n            checkArgument(mapping.getEnd() > mapping.getStart(), format(\n                    \"End mapping '%s' for column '%s' is less than or equal to start '%s'\",\n                    mapping.getEnd(),","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/raw/RawRowEncoder.java#L77-L113","documentation":"RawRowEncoder validates each Kafka column mapping at construction: the declared mapping byte length must equal the column type's fixed size, unless the column is VARCHAR (which may vary). When they mismatch it throws IndexOutOfBoundsException with the mapping length, expected length, and column name.","triggerScenarios":"Creating a raw-encoder Kafka table where a topic descriptor column mapping declares a byte range whose length differs from the column's fixed type size (e.g. BIGINT with an 8-byte type mapped to a 4-byte range).","commonSituations":"Hand-edited Kafka topic description JSON in the connector properties file; copy-pasted mappings from another table after changing a column from BIGINT to INTEGER/DATE; forgetting VARCHAR is the only variable-length exempt type.","solutions":["Fix the mapping in the Kafka topic definition so the byte range length matches the column type's size (e.g. BIGINT needs 8 bytes: 'start'-'end' spanning 8).","Change the column type in the CREATE TABLE to one whose size matches the existing mapping.","Use VARCHAR for the column if the data length is genuinely variable, since VARCHAR is exempt from the length check."],"exampleFix":"// before (topic definition)\n\"mapping\": \"0-3\", \"type\": \"BIGINT\"\n// after\n\"mapping\": \"0-7\", \"type\": \"BIGINT\"","handlingStrategy":"validation","validationCode":"// before creating the Kafka table, per column\nlong declared = end - start;            // mapping byte range length\nlong required = typeSize;               // BIGINT=8, INTEGER=4, etc.\nboolean ok = declared == required || isVarchar(type);\nif (!ok) throw new IllegalArgumentException(\n    \"Mapping length \" + declared + \" != type size \" + required);\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a mapping table of type size vs required byte span (BIGINT:8, INTEGER:4, BOOLEAN:1, etc.).","Regenerate table definitions from a script instead of hand-editing mapping strings.","Only rely on the VARCHAR exemption for genuinely variable-length data."],"tags":["kafka","encoder","column-mapping","table-definition"],"backgroundTag":"invalid-column-mapping","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"}