{"record":{"id":"e24ad57741a8e1cd","repo":"prestodb/presto","slug":"value-d-exceeds-max-byte","errorCode":null,"errorMessage":"Value %d exceeds MAX_BYTE","messagePattern":"Value (.+?) exceeds MAX_BYTE","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/TinyintType.java","lineNumber":152,"sourceCode":"    }\n\n    @Override\n    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();","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TinyintType.java#L134-L170","documentation":"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.","triggerScenarios":"Calling writeLong(blockBuilder, value) with value > 127, e.g. writing an INTEGER/BIGINT column's value into a TINYINT block without range checking.","commonSituations":"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.","solutions":["Range-check the value against [-128, 127] before writing; fail or clamp the query with a proper cast instead.","Use SMALLINT/INTEGER/BIGINT types if the data can exceed 127.","Apply an explicit CAST in the query so overflow becomes a clean user-facing error rather than an internal exception."],"exampleFix":"// before\nTINYINT.writeLong(blockBuilder, value);\n// after\nif (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {\n    TINYINT.writeLong(blockBuilder, value);\n} else {\n    throw new PrestoException(INVALID_CAST_ARGUMENT, \"Value out of TINYINT range: \" + value);\n}","handlingStrategy":"validation","validationCode":"if (value > Byte.MAX_VALUE) {\n    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, \"Value \" + value + \" exceeds 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 overflow: \" + value, e);\n}","preventionTips":["Range-check integer data before coercing to TINYINT in connectors.","Prefer explicit CAST in SQL so overflow is reported as a query error.","Widen the column type when source data can exceed [-128, 127]."],"tags":["presto","tinyint","overflow","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"}