{"record":{"id":"a910fad0b794152e","repo":"prestodb/presto","slug":"value-d-exceeds-max-int","errorCode":null,"errorMessage":"Value %d exceeds MAX_INT","messagePattern":"Value (.+?) exceeds MAX_INT","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/IntegerType.java","lineNumber":48,"sourceCode":"    {\n        super(parseTypeSignature(StandardTypes.INTEGER));\n    }\n\n    @Override\n    public Object getObjectValue(SqlFunctionProperties properties, Block block, int position)\n    {\n        if (block.isNull(position)) {\n            return null;\n        }\n\n        return block.getInt(position);\n    }\n\n    @Override\n    public final void writeLong(BlockBuilder blockBuilder, long value)\n    {\n        if (value > Integer.MAX_VALUE) {\n            throw new GenericInternalException(format(\"Value %d exceeds MAX_INT\", value));\n        }\n        else if (value < Integer.MIN_VALUE) {\n            throw new GenericInternalException(format(\"Value %d is less than MIN_INT\", value));\n        }\n\n        blockBuilder.writeInt((int) value).closeEntry();\n    }\n\n    @Override\n    @SuppressWarnings(\"EqualsWhichDoesntCheckParameterClass\")\n    public boolean equals(Object other)\n    {\n        return other == INTEGER;\n    }\n\n    @Override\n    public int hashCode()\n    {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/IntegerType.java#L30-L66","documentation":"IntegerType.writeLong writes a 32-bit int into the block builder, so a long value above Integer.MAX_VALUE cannot be represented; it throws GenericInternalException 'Value %d exceeds MAX_INT'. Unlike the MIN branch, note that MAX_VALUE itself is fine — only strictly greater values fail.","triggerScenarios":"Calling blockBuilder.writeLong(value) on an IntegerType block with value > 2147483647; feeding BIGINT/LONG column values into an INTEGER-typed writer without a range check.","commonSituations":"Reading a BIGINT column and writing it to an INTEGER column (e.g. table copy or implicit-ish casts in custom code); ETL where the source column was widened but the sink is INT; counters/ids overflowing int range.","solutions":["Range-check the long and either error out or null the value before writeLong","Cast to INTEGER in SQL first so an overflow produces the engine's standard cast error/NULL semantics","Change the target column to BIGINT if values legitimately exceed int range","Use Ints.checkedCast (or equivalent) so the failure point is explicit and controlled"],"exampleFix":"// before\nintegerBlockBuilder.writeLong(bigintValue); // GenericInternalException if > MAX_INT\n// after\nif (bigintValue > Integer.MAX_VALUE || bigintValue < Integer.MIN_VALUE) {\n    integerBlockBuilder.appendNull();\n} else {\n    integerBlockBuilder.writeLong(bigintValue);\n}","handlingStrategy":"type-guard","validationCode":"public static boolean fitsInInt(long value) {\n    return value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE;\n}\n// guard before: integerBlockBuilder.writeLong(value)","typeGuard":"public static Integer toIntOrNull(Long value) {\n    return (value == null || value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) ? null : value.intValue();\n}","tryCatchPattern":"try {\n    integerBlockBuilder.writeLong(value);\n} catch (GenericInternalException e) {\n    integerBlockBuilder.appendNull(); // or log/route overflow row\n}","preventionTips":["Range-check longs before writing into INTEGER blocks","Use SQL CAST to INTEGER for defined overflow semantics","Prefer BIGINT columns when source values can exceed int range"],"tags":["presto","integer","overflow","block-builder"],"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"}