prestodb/presto · error · GenericInternalException

Value %d is less than MIN_BYTE

Error message

Value %d is less than MIN_BYTE

What it means

TinyintType.writeLong also rejects values smaller than Byte.MIN_VALUE (-128); a long below that cannot be stored in the one-byte TINYINT representation, so a GenericInternalException is thrown to avoid silent wrap-around.

Source

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

    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();
    }

    public static long hash(byte value)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Range-check the value against [-128, 127] before writing and surface a PrestoException for out-of-range data.
  2. Widen the column type to SMALLINT/INTEGER/BIGINT to accommodate negative values.
  3. Clamp values at the source if truncation semantics are acceptable and documented.

Example fix

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

Strategy: validation

Validate before calling

if (value < Byte.MIN_VALUE) {
    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Value " + value + " below 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 underflow: " + value, e);
}

Prevention

When it happens

Trigger: Calling writeLong(blockBuilder, value) with value < -128, e.g. pushing negative BIGINT data into a TINYINT-typed sink.

Common situations: Connector writes of negative sensor/ledger values mapped to TINYINT; downcasts of underflowing arithmetic results; mismatched column types after schema evolution.

Related errors


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