prestodb/presto · error · IndexOutOfBoundsException
Mapping length '%s' is not equal to expected length '%s' for
Error message
Mapping length '%s' is not equal to expected length '%s' for column '%s'
What it means
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.
Source
Thrown at presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/raw/RawRowEncoder.java:95
private final List<ColumnMapping> columnMappings;
private final ByteBuffer buffer;
public RawRowEncoder(ConnectorSession session, List<EncoderColumnHandle> columnHandles)
{
super(session, columnHandles);
for (EncoderColumnHandle handle : this.columnHandles) {
checkArgument(isSupportedType(handle.getType()), "Unsupported column type '%s' for column '%s'", handle.getType().getDisplayName(), handle.getName());
checkArgument(handle.getFormatHint() == null, "Unexpected format hint '%s' defined for column '%s'", handle.getFormatHint(), handle.getName());
}
// parse column mappings from column handles
this.columnMappings = this.columnHandles.stream().map(ColumnMapping::new).collect(toImmutableList());
for (ColumnMapping mapping : this.columnMappings) {
if (mapping.getLength() != mapping.getFieldType().getSize() && !isVarcharType(mapping.getType())) {
throw new IndexOutOfBoundsException(format(
"Mapping length '%s' is not equal to expected length '%s' for column '%s'",
mapping.getLength(),
mapping.getFieldType().getSize(),
mapping.getName()));
}
}
// check that column mappings don't overlap and that there are no gaps
int position = 0;
for (ColumnMapping mapping : this.columnMappings) {
checkArgument(mapping.getStart() == position, format(
"Start mapping '%s' for column '%s' does not equal expected mapping '%s'",
mapping.getStart(),
mapping.getName(),
position));
checkArgument(mapping.getEnd() > mapping.getStart(), format(
"End mapping '%s' for column '%s' is less than or equal to start '%s'",
mapping.getEnd(),View on GitHub (pinned to 55bb57d202)
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.
Example fix
// before (topic definition) "mapping": "0-3", "type": "BIGINT" // after "mapping": "0-7", "type": "BIGINT"
Defensive patterns
Strategy: validation
Validate before calling
// before creating the Kafka table, per column
long declared = end - start; // mapping byte range length
long required = typeSize; // BIGINT=8, INTEGER=4, etc.
boolean ok = declared == required || isVarchar(type);
if (!ok) throw new IllegalArgumentException(
"Mapping length " + declared + " != type size " + required);
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- No mapping defined for column '%s'
- Invalid mapping for column '%s'
- Unable to parse '%s' offset for column '%s'
- unexpected internal column '%s'
- Column '%s' does not support 'null' value
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/2857b37429255afc.
Report an issue: GitHub.