prestodb/presto · error · IllegalArgumentException

Type must be a DecimalType for DecimalVector

Error message

Type must be a DecimalType for DecimalVector

What it means

assignBlockFromDecimalVector requires the Presto Type supplied alongside the Arrow DecimalVector to be a DecimalType, because it must write decimal values with matching precision/scale. If the Type is anything else, it throws IllegalArgumentException('Type must be a DecimalType for DecimalVector'). It indicates a mismatch between the Arrow vector's type and the declared Presto column type.

Source

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

        }
    }

    public void assignBlockFromBigIntVector(BigIntVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)
    {
        for (int i = startIndex; i < endIndex; i++) {
            if (vector.isNull(i)) {
                builder.appendNull();
            }
            else {
                type.writeLong(builder, vector.get(i));
            }
        }
    }

    public void assignBlockFromDecimalVector(DecimalVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)
    {
        if (!(type instanceof DecimalType)) {
            throw new IllegalArgumentException("Type must be a DecimalType for DecimalVector");
        }

        DecimalType decimalType = (DecimalType) type;

        for (int i = startIndex; i < endIndex; i++) {
            if (vector.isNull(i)) {
                builder.appendNull();
            }
            else {
                BigDecimal decimal = vector.getObject(i); // Get the BigDecimal value
                if (decimalType.isShort()) {
                    builder.writeLong(decimal.unscaledValue().longValue());
                }
                else {
                    Slice slice = Decimals.encodeScaledValue(decimal);
                    decimalType.writeSlice(builder, slice, 0, slice.length());
                }
            }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the type mapping so DECIMAL Arrow columns map to Presto DecimalType with matching precision/scale
  2. Refresh or correct the schema metadata (connector table definition) so the declared type matches the Arrow data
  3. If decimal precision/scale differs from expected, cast the column or adjust the DecimalType parameters
  4. Verify the Type passed into assignBlockFromValueVector comes from the same schema as the Arrow vectors

Example fix

// before
Type type = BIGINT; // wrong mapping for DecimalVector
builder.assignBlockFromDecimalVector(decimalVector, type, bb, 0, n);
// after
Type type = DecimalType.createDecimalType(precision, scale);
builder.assignBlockFromDecimalVector(decimalVector, type, bb, 0, n);
Defensive patterns

Strategy: validation

Validate before calling

// verify declared Presto type matches the Arrow vector before building blocks
checkArgument(type instanceof DecimalType,
    "Column %s is DecimalVector but declared type is %s", vector.getName(), type.getDisplayName());
checkArgument(((DecimalType) type).getPrecision() == vector.getField().getPrecision()
    && ((DecimalType) type).getScale() == vector.getField().getScale(),
    "Decimal precision/scale mismatch for column %s", vector.getName());

Type guard

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

Try / catch

try {
    blockBuilder.assignBlockFromDecimalVector(decimalVector, type, builder, 0, n);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("must be a DecimalType")) {
        throw new SchemaMismatchException(vector.getName(), type, "DECIMAL", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling assignBlockFromValueVector (directly or via buildBlockFromFieldVector) with a DecimalVector while the mapped Presto Type is not DecimalType — e.g. it resolved to BIGINT, DOUBLE, or UNKNOWN due to a bad schema mapping.

Common situations: Connector type-mapping table maps an Arrow decimal column to the wrong Presto type; stale/incorrect column metadata from a catalog or schema registry; hand-written conversion code passing the wrong Type.

Related errors


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