{"record":{"id":"39ed884ea8b38367","repo":"prestodb/presto","slug":"decimal-exceeds-128-bits","errorCode":null,"errorMessage":"Decimal exceeds 128 bits","messagePattern":"Decimal exceeds 128 bits","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/DecimalInputStream.java","lineNumber":61,"sourceCode":"\n    @Override\n    public void seekToCheckpoint(DecimalStreamCheckpoint checkpoint)\n            throws IOException\n    {\n        input.seekToCheckpoint(checkpoint.getInputStreamCheckpoint());\n    }\n\n    public void nextLongDecimal(Slice result)\n            throws IOException\n    {\n        long b;\n        long offset = 0;\n        long low = 0;\n        long high = 0;\n        do {\n            b = input.read();\n            if (offset == 126 && ((b & 0x80) > 0 || (b & 0x7f) > 3)) {\n                throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Decimal exceeds 128 bits\");\n            }\n\n            if (offset < 63) {\n                low |= (b & 0x7f) << offset;\n            }\n            else if (offset == 63) {\n                low |= (b & 0x01) << offset;\n                high |= (b & 0x7f) >>> 1;\n            }\n            else {\n                high |= (b & 0x7f) << (offset - 64);\n            }\n            offset += 7;\n        }\n        while ((b & 0x80) > 0);\n\n        boolean negative = (low & 0x01) == 1;\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/DecimalInputStream.java#L43-L79","documentation":"Thrown by DecimalInputStream.nextLongDecimal when a varint-encoded decimal requires more than 128 bits of significand: at offset==126 the code checks whether the current byte's high bit signals more bytes or whether its low 7 bits exceed 3, either of which would overflow a 128-bit (16-byte) decimal. ORC DECIMAL(38,x) values must fit in 128 bits; larger values mean the file's data does not match the declared schema.","triggerScenarios":"Reading a LONG_DECIMAL column via nextLongDecimal where the encoded varint has a byte at position 126 with the continuation bit set, or with a 7-bit payload > 3 (i.e. the value needs > 128 bits).","commonSituations":"A table schema defined with DECIMAL(38,p) but data written by a system allowing wider precision; corrupt/garbage bytes interpreted as an over-long varint; writers producing decimals incompatible with the ORC type declared in the footer.","solutions":["Compare the ORC footer type (orc-dump) with the table schema; widen the Presto table column (e.g. up to DECIMAL(38,x)) or fix the writer to emit values within 128 bits.","Locate and rewrite offending rows: filter source data by the column to find values exceeding DECIMAL(38,x) range and clamp/round them before rewriting.","If bytes are garbage, treat the file as corrupt and regenerate it from source.","Ensure the producing engine's decimal precision matches ORC's 128-bit limit (e.g. avoid writing 40-digit decimals into a 38-digit column)."],"exampleFix":"// before: writing oversized decimal\nBigDecimal v = new BigDecimal(\"123456789012345678901234567890123456789012345\"); // 45 digits\n// after: clamp to the declared precision before writing\nBigDecimal v2 = v.setScale(scale, RoundingMode.HALF_UP)\n    .min(new BigDecimal(\"9.9999999999999999999999999999999999999E+37\"));","handlingStrategy":"validation","validationCode":"// on the write side, guarantee values fit DECIMAL(38,x)\nBigDecimal max = new BigDecimal(\"1\").movePointLeft(scale)\n    .multiply(new BigDecimal(\"9\").repeat(38));\nif (value.abs().compareTo(max) > 0) {\n    throw new IllegalArgumentException(\"value exceeds 128-bit decimal: \" + value);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return decimalStream.nextLongDecimal(values);\n} catch (OrcCorruptionException e) {\n    if (e.getMessage().contains(\"exceeds 128 bits\")) {\n        throw new SchemaMismatchException(\"data wider than declared DECIMAL(38,x)\", e);\n    }\n    throw e;\n}","preventionTips":["Clamp/round decimals to declared precision+scale in ETL before writing.","Match the producing system's precision settings to the ORC column type.","Compare footer types with table schema during ingest validation.","Use DECIMAL(38,x) columns when source precision is unbounded."],"tags":["orc","decimal","overflow","schema-mismatch"],"backgroundTag":"decimal-value-out-of-range","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"}