{"record":{"id":"521a58d0d8cc5299","repo":"prestodb/presto","slug":"value-d-is-less-than-min-byte","errorCode":null,"errorMessage":"Value %d is less than MIN_BYTE","messagePattern":"Value (.+?) is less than MIN_BYTE","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/TinyintType.java","lineNumber":155,"sourceCode":"    public byte getByte(Block block, int position)\n    {\n        return block.getByte(position);\n    }\n\n    @Override\n    public long getLongUnchecked(UncheckedBlock block, int internalPosition)\n    {\n        return (long) block.getByteUnchecked(internalPosition);\n    }\n\n    @Override\n    public void writeLong(BlockBuilder blockBuilder, long value)\n    {\n        if (value > Byte.MAX_VALUE) {\n            throw new GenericInternalException(format(\"Value %d exceeds MAX_BYTE\", value));\n        }\n        else if (value < Byte.MIN_VALUE) {\n            throw new GenericInternalException(format(\"Value %d is less than MIN_BYTE\", value));\n        }\n\n        blockBuilder.writeByte((int) value).closeEntry();\n    }\n\n    @Override\n    public boolean equals(Object other)\n    {\n        return other == TINYINT;\n    }\n\n    @Override\n    public int hashCode()\n    {\n        return getClass().hashCode();\n    }\n\n    public static long hash(byte value)","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TinyintType.java#L137-L173","documentation":"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.","triggerScenarios":"Calling writeLong(blockBuilder, value) with value < -128, e.g. pushing negative BIGINT data into a TINYINT-typed sink.","commonSituations":"Connector writes of negative sensor/ledger values mapped to TINYINT; downcasts of underflowing arithmetic results; mismatched column types after schema evolution.","solutions":["Range-check the value against [-128, 127] before writing and surface a PrestoException for out-of-range data.","Widen the column type to SMALLINT/INTEGER/BIGINT to accommodate negative values.","Clamp values at the source if truncation semantics are acceptable and documented."],"exampleFix":"// before\nTINYINT.writeLong(blockBuilder, value);\n// after\nif (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {\n    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, \"Value out of TINYINT range: \" + value);\n}\nTINYINT.writeLong(blockBuilder, value);","handlingStrategy":"validation","validationCode":"if (value < Byte.MIN_VALUE) {\n    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, \"Value \" + value + \" below TINYINT range\");\n}","typeGuard":"boolean fitsTinyint(long v) { return v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE; }","tryCatchPattern":"try {\n    TINYINT.writeLong(blockBuilder, value);\n} catch (GenericInternalException e) {\n    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, \"TINYINT underflow: \" + value, e);\n}","preventionTips":["Check both bounds (MIN and MAX) with one guard before writeLong.","Use SMALLINT/INTEGER for data with negative values outside [-128, 127].","Test connector type mapping with boundary values -128, -129, 127, 128."],"tags":["presto","tinyint","underflow","serialization"],"backgroundTag":"integer-overflow","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}