{"record":{"id":"f616f5bd3575b805","repo":"prestodb/presto","slug":"unable-to-read-binary-type-decimal-of-size","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/delta/BinaryShortDecimalDeltaValuesDecoder.java","lineNumber":57,"sourceCode":"        requireNonNull(bufferInputStream, \"bufferInputStream is null\");\n        delegate = new BinaryDeltaValuesDecoder(encoding, valueCount, bufferInputStream);\n    }\n\n    @Override\n    public void readNext(long[] values, int offset, int length)\n            throws IOException\n    {\n        BinaryValuesDecoder.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            throws IOException\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;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parquet/src/main/java/com/facebook/presto/parquet/batchreader/decoders/delta/BinaryShortDecimalDeltaValuesDecoder.java#L39-L75","documentation":"BinaryShortDecimalDeltaValuesDecoder reads DELTA-encoded BINARY values and converts each to a short decimal (max precision 18, fitting in 8 bytes). If any value's binary length exceeds 8 bytes, it cannot represent a valid short decimal unscaled value, so a ParquetDecodingException is thrown listing the offending size.","triggerScenarios":"readNext() iterates values and finds positionLength > 8 for a value, meaning the BINARY bytes encode an unscaled decimal too large for a short decimal column.","commonSituations":"Parquet file declares DECIMAL(precision<=18) but writer stored over-length binary values (schema drift, wrong annotation); reading a file whose decimal column was written as a longer precision decimal and the reader forces it into short decimal; hand-modified schemas where the file's precision (e.g. 38) no longer matches the table's.","solutions":["Verify the Parquet schema's DECIMAL precision/annotation matches the stored data (parquet-tools dump the column)","Read the column as a long/decimal with wider precision if values exceed 18 digits, or use a session/catalog setting that maps to long decimals","Re-write the file with the correct DECIMAL annotation matching the table schema","If values should be short decimals, reject/repair rows with oversized values at write time"],"exampleFix":"// before: column annotated DECIMAL(38) but read as short decimal\n// after: align read type with file precision\n//   SELECT CAST(col AS DECIMAL(38,10)) FROM ... -- forces long-decimal decoder\n// or rewrite file: SELECT CAST(col AS DECIMAL(18,6)) ...","handlingStrategy":"validation","validationCode":"// Ensure the declared decimal precision fits a short decimal (<= 18):\n// prec := file schema DECIMAL precision; if prec > 18 read as long decimal\n// parquet-tools schema file.parquet | grep DECIMAL","typeGuard":null,"tryCatchPattern":"try {\n    block = decoder.readNext(length);\n} catch (ParquetDecodingException e) {\n    if (e.getMessage().startsWith(\"Unable to read BINARY type decimal of size\")) {\n        // re-run the read with a long-decimal decoder\n    }\n    throw e;\n}","preventionTips":["Keep table DECIMAL precision aligned with the file's schema annotation","Never shrink declared precision below what the writer used","Validate decimal columns with parquet-tools during ingest","Write-time check: assert unscaled values fit 8 bytes for short decimals"],"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"}