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
- Clamp or range-check the value before writing: if (v > 32767 || v < -32768) handle overflow.
- Cast to SMALLINT in SQL so the engine performs defined cast semantics (with error or saturate per config).
- 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
- Range-check longs against SMALLINT bounds before writing.
- Match writer type to declared column type; don't downcast silently.
- Use explicit SQL CAST to SMALLINT so defined overflow semantics apply.
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
- Value %d is less than MIN_SHORT
- NUMERIC_VALUE_OUT_OF_RANGE
- TimestampWithTimeZone overflow: %s ms
- Value %d exceeds MAX_INT
- toEpochMillis is not supported for TIMESTAMP(
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/392e095025c0bbf5.
Report an issue: GitHub.