{"record":{"id":"c589e7ca1b90591c","repo":"prestodb/presto","slug":"decoded-value-out-of-range-for-a-32bit-number-c589e7","errorCode":null,"errorMessage":"Decoded value out of range for a 32bit number","messagePattern":"Decoded value out of range for a 32bit number","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java","lineNumber":374,"sourceCode":"\n    @Override\n    public void next(int[] values, int items)\n            throws IOException\n    {\n        int offset = 0;\n        while (items > 0) {\n            if (used == numLiterals) {\n                numLiterals = 0;\n                used = 0;\n                readValues();\n            }\n\n            int chunkSize = min(numLiterals - used, items);\n            for (int i = 0; i < chunkSize; i++) {\n                long literal = literals[used + i];\n                int value = (int) literal;\n                if (literal != value) {\n                    throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Decoded value out of range for a 32bit number\");\n                }\n                values[offset + i] = value;\n            }\n            used += chunkSize;\n            offset += chunkSize;\n            items -= chunkSize;\n        }\n    }\n\n    @Override\n    public void next(short[] values, int items)\n            throws IOException\n    {\n        int offset = 0;\n        while (items > 0) {\n            if (used == numLiterals) {\n                numLiterals = 0;\n                used = 0;","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java#L356-L392","documentation":"LongInputStreamV2.next(int[], items) buffers decoded RLEv2 literals as longs and narrows each to an int when filling the caller's int[] column. If a literal's value changes when narrowed to 32 bits, the stream's values cannot be represented as ints and Presto throws OrcCorruptionException rather than silently truncating.","triggerScenarios":"Reading an INTEGER-typed ORC column whose RLEv2 literals exceed Integer.MIN_VALUE..Integer.MAX_VALUE — caused by corrupt data, an integer-overflowing DELTA run, or a writer that stored values wider than the declared column type.","commonSituations":"Files written by buggy writers (e.g. delta encoding overflowing), schema drift where a BIGINT column is read as INT, corrupted delta arithmetic in patched/delta streams, or tool version incompatibilities between writer and reader.","solutions":["Check the ORC footer's declared column type; align the Presto table schema with it (use BIGINT if values exceed int range).","Validate/re-copy the file; run orc-tools scan to locate the corrupt stripe.","Re-write the file with a current ORC writer if the producer overflowed delta values.","If widening the type is not possible, filter or coerce upstream (read as BIGINT then CAST).","Upgrade Presto if a known decoding bug matches your writer version."],"exampleFix":"// before\nCREATE TABLE t (id INT) WITH (external_location = 's3://bucket/wide.orc'); -- fails\n\n// after: widen the column to match actual data range\nCREATE TABLE t (id BIGINT) WITH (external_location = 's3://bucket/wide.orc');","handlingStrategy":"validation","validationCode":"// Check declared type vs value range before query:\n// orc-tools meta data.orc  -> confirm column is INTEGER;\n// orc-scan data.orc | awk '$1 < -2147483648 || $1 > 2147483647 {bad++} END {exit bad>0}'","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(\"SELECT int_col FROM table\");\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == OrcErrorCode.ORC_BAD_DATA.getCode()) {\n        // retry with the column read as BIGINT\n    } else {\n        throw e;\n    }\n}","preventionTips":["Map ORC INT columns to Presto INTEGER and BIGINT columns to BIGINT — never downcast in schema.","Detect producer-side delta-overflow bugs by validating files with orc-tools after writes.","Keep writer libraries (Hive/Spark ORC) current.","Checksum files in transit to catch corruption that mutates literals.","Use TRY_CAST in downstream SQL rather than relying on narrow storage types."],"tags":["orc","data-corruption","int-overflow","presto"],"backgroundTag":"orc-column-type-mismatch","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"}