prestodb/presto · error · GenericInternalException

Value %d exceeds MAX_SHORT

Error message

Value %d exceeds MAX_SHORT

What it means

SmallintType.writeLong validates that the long value fits into a 16-bit signed short. Values greater than Short.MAX_VALUE (32767) throw GenericInternalException "Value %d exceeds MAX_SHORT". It guards the block writer from silently truncating out-of-range values into SMALLINT storage.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java:146

    }

    @Override
    public long getLong(Block block, int position)
    {
        return (long) block.getShort(position);
    }

    @Override
    public long getLongUnchecked(UncheckedBlock block, int internalPosition)
    {
        return (long) block.getShortUnchecked(internalPosition);
    }

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

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

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

    @Override
    public int hashCode()
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Clamp or range-check the value before writing: if (v > 32767 || v < -32768) handle overflow.
  2. Cast to SMALLINT in SQL so the engine performs defined cast semantics (with error or saturate per config).
  3. Widen the target column to INTEGER/BIGINT if larger values are legitimate.

Example fix

// before
smallintType.writeLong(blockBuilder, bigValue);
// after
if (bigValue > Short.MAX_VALUE) throw new IllegalArgumentException(...);
smallintType.writeLong(blockBuilder, bigValue);
Defensive patterns

Strategy: validation

Validate before calling

if (value > Short.MAX_VALUE) { /* clamp or widen column type */ }

Type guard

boolean fitsSmallint(long v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }

Try / catch

try { smallintType.writeLong(blockBuilder, value); } catch (GenericInternalException e) { /* widen to IntegerType/BigIntegerType or clamp */ }

Prevention

When it happens

Trigger: Calling SmallintType.writeLong(blockBuilder, value) with value > 32767, e.g. writing an INTEGER/BIGINT column value into a SMALLINT block without casting.

Common situations: Connector writers mapping wider integer types to SMALLINT columns; UDFs emitting values beyond smallint range; table schema changed to SMALLINT while producers still emit larger values.

Related errors


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