prestodb/presto · error · GenericInternalException

Value %d exceeds MAX_BYTE

Error message

Value %d exceeds MAX_BYTE

What it means

TinyintType.writeLong serializes a 64-bit long into a single-byte TINYINT block entry. If the value is greater than Byte.MAX_VALUE (127) it cannot be represented, so a GenericInternalException is thrown to prevent silent truncation.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/TinyintType.java:152

    }

    @Override
    public byte getByte(Block block, int position)
    {
        return block.getByte(position);
    }

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

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

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

    @Override
    public boolean equals(Object other)
    {
        return other == TINYINT;
    }

    @Override
    public int hashCode()
    {
        return getClass().hashCode();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Range-check the value against [-128, 127] before writing; fail or clamp the query with a proper cast instead.
  2. Use SMALLINT/INTEGER/BIGINT types if the data can exceed 127.
  3. Apply an explicit CAST in the query so overflow becomes a clean user-facing error rather than an internal exception.

Example fix

// before
TINYINT.writeLong(blockBuilder, value);
// after
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
    TINYINT.writeLong(blockBuilder, value);
} else {
    throw new PrestoException(INVALID_CAST_ARGUMENT, "Value out of TINYINT range: " + value);
}
Defensive patterns

Strategy: validation

Validate before calling

if (value > Byte.MAX_VALUE) {
    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Value " + value + " exceeds TINYINT range");
}

Type guard

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

Try / catch

try {
    TINYINT.writeLong(blockBuilder, value);
} catch (GenericInternalException e) {
    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "TINYINT overflow: " + value, e);
}

Prevention

When it happens

Trigger: Calling writeLong(blockBuilder, value) with value > 127, e.g. writing an INTEGER/BIGINT column's value into a TINYINT block without range checking.

Common situations: Connectors coercing wider integer columns to TINYINT during type mapping; user queries casting out-of-range literals; aggregation results exceeding byte range being written to TINYINT output.

Related errors


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