prestodb/presto · error · GenericInternalException

Value %d exceeds MAX_INT

Error message

Value %d exceeds MAX_INT

What it means

IntegerType.writeLong writes a 32-bit int into the block builder, so a long value above Integer.MAX_VALUE cannot be represented; it throws GenericInternalException 'Value %d exceeds MAX_INT'. Unlike the MIN branch, note that MAX_VALUE itself is fine — only strictly greater values fail.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/IntegerType.java:48

    {
        super(parseTypeSignature(StandardTypes.INTEGER));
    }

    @Override
    public Object getObjectValue(SqlFunctionProperties properties, Block block, int position)
    {
        if (block.isNull(position)) {
            return null;
        }

        return block.getInt(position);
    }

    @Override
    public final void writeLong(BlockBuilder blockBuilder, long value)
    {
        if (value > Integer.MAX_VALUE) {
            throw new GenericInternalException(format("Value %d exceeds MAX_INT", value));
        }
        else if (value < Integer.MIN_VALUE) {
            throw new GenericInternalException(format("Value %d is less than MIN_INT", value));
        }

        blockBuilder.writeInt((int) value).closeEntry();
    }

    @Override
    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
    public boolean equals(Object other)
    {
        return other == INTEGER;
    }

    @Override
    public int hashCode()
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Range-check the long and either error out or null the value before writeLong
  2. Cast to INTEGER in SQL first so an overflow produces the engine's standard cast error/NULL semantics
  3. Change the target column to BIGINT if values legitimately exceed int range
  4. Use Ints.checkedCast (or equivalent) so the failure point is explicit and controlled

Example fix

// before
integerBlockBuilder.writeLong(bigintValue); // GenericInternalException if > MAX_INT
// after
if (bigintValue > Integer.MAX_VALUE || bigintValue < Integer.MIN_VALUE) {
    integerBlockBuilder.appendNull();
} else {
    integerBlockBuilder.writeLong(bigintValue);
}
Defensive patterns

Strategy: type-guard

Validate before calling

public static boolean fitsInInt(long value) {
    return value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE;
}
// guard before: integerBlockBuilder.writeLong(value)

Type guard

public static Integer toIntOrNull(Long value) {
    return (value == null || value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) ? null : value.intValue();
}

Try / catch

try {
    integerBlockBuilder.writeLong(value);
} catch (GenericInternalException e) {
    integerBlockBuilder.appendNull(); // or log/route overflow row
}

Prevention

When it happens

Trigger: Calling blockBuilder.writeLong(value) on an IntegerType block with value > 2147483647; feeding BIGINT/LONG column values into an INTEGER-typed writer without a range check.

Common situations: Reading a BIGINT column and writing it to an INTEGER column (e.g. table copy or implicit-ish casts in custom code); ETL where the source column was widened but the sink is INT; counters/ids overflowing int range.

Related errors


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