prestodb/presto · error · IllegalArgumentException

Expected VarcharType but got {type.getClass().getName()}

Error message

Expected VarcharType but got {type.getClass().getName()}

What it means

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>').

Source

Thrown at presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java:490

    }

    public void assignBlockFromVarBinaryVector(VarBinaryVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)
    {
        for (int i = startIndex; i < endIndex; i++) {
            if (vector.isNull(i)) {
                builder.appendNull();
            }
            else {
                byte[] value = vector.get(i);
                type.writeSlice(builder, Slices.wrappedBuffer(value));
            }
        }
    }

    public void assignBlockFromVarCharVector(VarCharVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)
    {
        if (!(type instanceof VarcharType)) {
            throw new IllegalArgumentException("Expected VarcharType but got " + type.getClass().getName());
        }

        for (int i = startIndex; i < endIndex; i++) {
            if (vector.isNull(i)) {
                builder.appendNull();
            }
            else {
                // Directly create a Slice from the raw byte array
                byte[] rawBytes = vector.get(i);
                Slice slice = Slices.wrappedBuffer(rawBytes);
                // Write the Slice directly to the builder
                type.writeSlice(builder, slice);
            }
        }
    }

    public void assignBlockFromDateDayVector(DateDayVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the mapping so Arrow string columns map to Presto VarcharType
  2. Refresh or correct the connector schema metadata
  3. Cast the column to string on the producer side if a non-varchar type was intended
  4. Validate the Type before calling assignBlockFromValueVector

Example fix

// before
Type type = JSON; // mismatch for VarCharVector
// after
Type type = VarcharType.createVarcharType();
Defensive patterns

Strategy: validation

Validate before calling

checkArgument(type instanceof VarcharType,
    "Column %s is VarCharVector but declared type is %s", vector.getName(), type.getDisplayName());

Type guard

boolean isCompatiblePrestoType(ValueVector v, Type t) {
    if (v instanceof VarCharVector) {
        return t instanceof VarcharType;
    }
    return true;
}

Try / catch

try {
    blockBuilder.assignBlockFromVarCharVector(varCharVector, type, builder, 0, n);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Expected VarcharType")) {
        throw new SchemaMismatchException(vector.getName(), type, "VARCHAR", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/1709b06026a7d6a0. Report an issue: GitHub.