{"record":{"id":"98d7b0b9074277c6","repo":"prestodb/presto","slug":"unable-to-read-binary-type-decimal-of-size-98d7b0","errorCode":null,"errorMessage":"Unable to read BINARY type decimal of size ","messagePattern":"Unable to read BINARY type decimal of size ","errorType":"exception","errorClass":"ParquetDecodingException","httpStatus":null,"severity":"error","filePath":"presto-parquet/src/main/java/com/facebook/presto/parquet/batchreader/decoders/plain/BinaryShortDecimalPlainValuesDecoder.java","lineNumber":51,"sourceCode":"    {\n        requireNonNull(byteBuffer, \"buffer is null\");\n        delegate = new BinaryPlainValuesDecoder(byteBuffer, bufferOffset, length);\n    }\n\n    @Override\n    public void readNext(long[] values, int offset, int length)\n    {\n        ValueBuffer valueBuffer = delegate.readNext(length);\n        int bufferSize = valueBuffer.getBufferSize();\n        byte[] byteBuffer = new byte[bufferSize];\n        int[] offsets = new int[length + 1];\n        delegate.readIntoBuffer(byteBuffer, 0, offsets, 0, valueBuffer);\n\n        for (int i = 0; i < length; i++) {\n            int positionOffset = offsets[i];\n            int positionLength = offsets[i + 1] - positionOffset;\n            if (positionLength > 8) {\n                throw new ParquetDecodingException(\"Unable to read BINARY type decimal of size \" + positionLength + \" as a short decimal\");\n            }\n\n            values[offset + i] = getShortDecimalValue(byteBuffer, positionOffset, positionLength);\n        }\n    }\n\n    @Override\n    public void skip(int length)\n    {\n        checkArgument(length >= 0, \"invalid length %s\", length);\n        delegate.skip(length);\n    }\n\n    @Override\n    public long getRetainedSizeInBytes()\n    {\n        return INSTANCE_SIZE;\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parquet/src/main/java/com/facebook/presto/parquet/batchreader/decoders/plain/BinaryShortDecimalPlainValuesDecoder.java#L33-L69","documentation":"BinaryShortDecimalPlainValuesDecoder reads PLAIN-encoded BINARY values and converts each to a short decimal. Any value whose binary length exceeds 8 bytes cannot fit a short decimal unscaled value, so readNext throws a ParquetDecodingException with the offending size. This guards against silently truncating large decimals.","triggerScenarios":"readNext() over PLAIN-encoded binary decimal data where offsets[i+1]-offsets[i] > 8 for any value.","commonSituations":"DECIMAL columns written with precision > 18 (16-byte binary) but read/declared as short decimal; schema evolution where the table was altered to a smaller precision; external tables pointing at files with mismatched decimal annotations.","solutions":["Check the file's DECIMAL precision with parquet-tools and align the table schema/read type to it","Cast or read as a long decimal (precision > 18) instead of a short decimal","Rewrite the data with the correct short-decimal precision (<= 18) if values genuinely fit","Fail fast at write time by validating unscaled values fit in 8 bytes before encoding"],"exampleFix":"// before: DECIMAL(30,5) file read as short decimal -> exception\n// after: recreate table with matching precision\n//   CREATE TABLE t (col DECIMAL(30,5)) ... or CAST to DECIMAL(30,5) on read","handlingStrategy":"validation","validationCode":"// Before mapping the column to a short decimal, check its declared precision:\n// if (precision > 18) use long decimal path\n// parquet-tools schema file.parquet | grep 'DECIMAL'","typeGuard":"boolean fitsShortDecimal(int declaredPrecision) { return declaredPrecision <= 18; }","tryCatchPattern":"try {\n    decoder.readNext(length);\n} catch (ParquetDecodingException e) {\n    if (e.getMessage().contains(\"as a short decimal\")) {\n        // switch to a long-decimal decoder for this column\n    }\n    throw e;\n}","preventionTips":["Match table schema precision to the file's DECIMAL annotation","Avoid ALTER TABLE ... shrinking precision on external Parquet tables","Audit external table files with parquet-tools at registration","Cast explicitly to a wider decimal when values may exceed 18 digits"],"tags":["parquet","decimal","decoding"],"backgroundTag":"decimal-precision-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"}