prestodb/presto · error · RcFileCorruptionException

First column value length is negative

Error message

First column value length is negative

What it means

In RCFile run-length encoding of value lengths, a negative length encodes a run or terminator and requires a previously seen lastValueLength to resolve. If the very first decoded length for a column is negative there is no prior value to reference, so the reader throws RcFileCorruptionException.

Source

Thrown at presto-rcfile/src/main/java/com/facebook/presto/rcfile/RcFileReader.java:638

                int valueLength = readNextValueLength();
                currentOffset += valueLength;
            }
        }

        private int readNextValueLength()
                throws IOException
        {
            if (runLength > 0) {
                runLength--;
                return lastValueLength;
            }

            int valueLength = toIntExact(readVInt(lengthsInput));

            // negative length is used to encode a run or the last value
            if (valueLength < 0) {
                if (lastValueLength == -1) {
                    throw new RcFileCorruptionException("First column value length is negative");
                }
                runLength = (~valueLength) - 1;
                return lastValueLength;
            }

            runLength = 0;
            lastValueLength = valueLength;
            return valueLength;
        }

        private Slice getDataBuffer()
                throws IOException
        {
            if (compressed) {
                if (decompressedBuffer.length < uncompressedDataSize) {
                    decompressedBuffer = new byte[uncompressedDataSize];
                }
                Slice buffer = Slices.wrappedBuffer(decompressedBuffer, 0, uncompressedDataSize);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Treat the file as corrupt and re-generate or re-copy it from the source
  2. Confirm the reader and writer versions/Hive compatibility match
  3. Verify you are not seeking to a non-sync-bound offset inside the file
  4. Catch RcFileCorruptionException and skip/report the offending file
Defensive patterns

Strategy: try-catch

Try / catch

try { reader.read(); }
catch (RcFileCorruptionException e) {
    if (e.getMessage().contains("value length is negative")) {
        // mark file/stripe corrupt; skip or re-generate
    } else { throw e; }
}

Prevention

When it happens

Trigger: Reading a column whose first encoded value length is negative — i.e. the length stream starts with run-length metadata instead of an actual length, which only happens when the stream is misaligned or corrupt.

Common situations: Files written by buggy or incompatible RCFile writers; seeking into the middle of a compressed stream so the length stream starts mid-run; byte-level corruption in the column length stream.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/41407edcde09e1e7. Report an issue: GitHub.