{"record":{"id":"6c8f06bae30f670e","repo":"prestodb/presto","slug":"decoded-value-out-of-range-for-a-16bit-number-6c8f06","errorCode":null,"errorMessage":"Decoded value out of range for a 16bit number","messagePattern":"Decoded value out of range for a 16bit number","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java","lineNumber":401,"sourceCode":"\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;\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                short value = (short) literal;\n                if (literal != value) {\n                    throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Decoded value out of range for a 16bit number\");\n                }\n                values[offset + i] = value;\n            }\n            used += chunkSize;\n            offset += chunkSize;\n            items -= chunkSize;\n        }\n    }\n\n    @Override\n    public Class<LongStreamV2Checkpoint> getCheckpointType()\n    {\n        return LongStreamV2Checkpoint.class;\n    }\n\n    @Override\n    public void seekToCheckpoint(LongStreamCheckpoint checkpoint)\n            throws IOException","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java#L383-L419","documentation":"LongInputStreamV2.next(short[], items) narrows each buffered long RLEv2 literal to a short for SMALLINT columns; when the narrowing alters the value (literal outside -32768..32767) Presto throws OrcCorruptionException, since the stream contents contradict the 16-bit column type.","triggerScenarios":"Reading a SMALLINT ORC column where a decoded literal (from DIRECT, DELTA, PATCHED_BASE or SHORT_REPEAT runs) does not fit in 16 bits — typically corrupt data or a writer that emitted out-of-range values for a short column.","commonSituations":"Corrupted stripe bytes, non-conforming third-party ORC writers, schema drift (column actually contains int-range values but schema says smallint), or files damaged in transfer/storage.","solutions":["Check the footer's column type and the actual value range; if values exceed smallint, map the column to INTEGER/BIGINT in Presto.","Validate the file with orc-tools and re-copy from source if bytes are corrupt.","Re-write the file with a conforming ORC writer if the producer emitted out-of-range shorts.","Use session/connector options to skip corrupt stripes when partial results are tolerable.","Upgrade the reader (Presto) or writer if a known ORC encoding bug applies."],"exampleFix":"// before: SMALLINT schema over data with larger values\nCREATE TABLE t (flag SMALLINT) WITH (external_location = 's3://bucket/bad.orc');\n\n// after: read at natural width, narrow explicitly where safe\nCREATE TABLE t (flag BIGINT) WITH (external_location = 's3://bucket/bad.orc');\nSELECT try_cast(flag AS SMALLINT) FROM t;","handlingStrategy":"validation","validationCode":"// Confirm values fit smallint before reading as SMALLINT:\n// orc-scan data.orc | awk '$1 < -32768 || $1 > 32767 {bad++} END {exit bad>0}'","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(\"SELECT smallint_col FROM table\");\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == OrcErrorCode.ORC_BAD_DATA.getCode()) {\n        // fall back: read column as BIGINT, coerce with try_cast\n    } else {\n        throw e;\n    }\n}","preventionTips":["Ensure the writer emits only in-range values for SMALLINT columns.","Keep Presto schema (SMALLINT) aligned with the ORC footer type; widen if data outgrows 16 bits.","Validate new files with orc-tools before publishing.","Verify checksums after file transfers to detect bit corruption.","Prefer reading at native width and narrowing in SQL (try_cast) over narrow storage types for untrusted data."],"tags":["orc","data-corruption","short-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"}