prestodb/presto · error · GenericInternalException
Value %d is less than MIN_SHORT
Error message
Value %d is less than MIN_SHORT
What it means
The underflow counterpart of writeLong validation in SmallintType: values below Short.MIN_VALUE (-32768) throw GenericInternalException "Value %d is less than MIN_SHORT". It prevents negative out-of-range values from being truncated when written to SMALLINT blocks.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java:149
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()
{
return getClass().hashCode();
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Range-check and clamp values to [-32768, 32767] before writing.
- Cast explicitly to SMALLINT via SQL cast so standard cast semantics apply.
- Change the column type to INTEGER/BIGINT to accommodate the value range.
Example fix
// before smallintType.writeLong(blockBuilder, negativeValue); // after smallintType.writeLong(blockBuilder, Math.max(Short.MIN_VALUE, Math.min(Short.MAX_VALUE, negativeValue)));
Defensive patterns
Strategy: validation
Validate before calling
if (value < Short.MIN_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
- Clamp negative values to Short.MIN_VALUE when saturation is intended.
- Verify producer ranges match SMALLINT schema (especially deltas/offsets that can go negative).
- Prefer INTEGER/BIGINT columns when values legitimately exceed 16 bits.
When it happens
Trigger: Calling SmallintType.writeLong(blockBuilder, value) with value < -32768, e.g. writing a negative BIGINT/INTEGER value into a SMALLINT block.
Common situations: Downcasting wider integer columns to SMALLINT in connector writers; negative computed values (deltas, offsets) exceeding smallint lower bound.
Related errors
- Value %d exceeds MAX_SHORT
- Value %d is less than MIN_INT
- nanos must be in range [0, 999_999_999]:
- Value %d is less than MIN_BYTE
- ELASTICSEARCH_TYPE_MISMATCH
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/0958b0b991d66a3b.
Report an issue: GitHub.