prestodb/presto · error · IllegalArgumentException

Offset is not monotonically ascending. offsets[%s]=%s, offse

Error message

Offset is not monotonically ascending. offsets[%s]=%s, offsets[%s]=%s

What it means

When building a MAP block, Presto requires the offsets array to be monotonically non-decreasing: offsets[i+1] must be >= offsets[i]. A negative entry count means the offsets went backwards, which would corrupt the key/value layout of the map block, so the library throws IllegalArgumentException during validation.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/AbstractMapBlock.java:485

        }

        public long getRetainedSizeInBytes()
        {
            return INSTANCE_SIZE + sizeOf(hashTables);
        }

        public void loadHashTables(int positionCount, int[] offsets, boolean[] mapIsNull, Block keyBlock, MethodHandle keyBlockHashCode)
        {
            int[] hashTables = new int[keyBlock.getPositionCount() * HASH_MULTIPLIER];
            Arrays.fill(hashTables, -1);

            verify(positionCount < offsets.length, "incorrect offsets size");

            for (int i = 0; i < positionCount; i++) {
                int keyOffset = offsets[i];
                int keyCount = offsets[i + 1] - keyOffset;
                if (keyCount < 0) {
                    throw new IllegalArgumentException(format("Offset is not monotonically ascending. offsets[%s]=%s, offsets[%s]=%s", i, offsets[i], i + 1, offsets[i + 1]));
                }
                if (mapIsNull != null && mapIsNull[i] && keyCount != 0) {
                    throw new IllegalArgumentException("A null map must have zero entries");
                }
                buildHashTable(
                        keyBlock,
                        keyOffset,
                        keyCount,
                        keyBlockHashCode,
                        hashTables,
                        keyOffset * HASH_MULTIPLIER,
                        keyCount * HASH_MULTIPLIER);
            }
            set(hashTables);
        }

        // This class intentionally does not implement hashcode and equals.
        // Any class using Hashtables as a field (MapBlock, MapBlockBuilder) should not include this class's implementation as this is

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the code that builds the offsets array so each offsets[i+1] = offsets[i] + entryCount for that map, keeping the array non-decreasing.
  2. Verify offsets[0] == 0 and offsets[length-1] == keyBlock.getPositionCount() before creating the block.
  3. Check that all nodes/clients run the same Presto version so serialized pages are not reinterpreted with different offsets semantics.
  4. If the error surfaces only after deserializing pages, validate offsets on the producer side before shipping the page.

Example fix

// before
int[] offsets = {0, 5, 3, 8}; // not monotonic
MapBlock.createBlockHelper(type, keyBlock, valueBlock, offsets, hashTables, null);
// after
int[] offsets = {0, 3, 5, 8}; // non-decreasing
Defensive patterns

Strategy: validation

Validate before calling

static void validateMapOffsets(int[] offsets, int positionCount) {
    for (int i = 0; i < positionCount; i++) {
        checkArgument(offsets[i + 1] >= offsets[i],
            "offsets must be non-decreasing: offsets[%d]=%d > offsets[%d]=%d",
            i, offsets[i], i + 1, offsets[i + 1]);
    }
    checkArgument(offsets[0] == 0, "offsets[0] must be 0");
}

Try / catch

try {
    Block mapBlock = buildMapBlock(keys, values, offsets);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("not monotonically ascending")) {
        throw new DataCorruptionException("invalid map offsets", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling MapBlock.createBlockHelper / mapType block builders with a hand-built offsets array where offsets[i+1] < offsets[i], or constructing a map block from serialized pages whose offsets were corrupted or miscomputed.

Common situations: Custom Block serialization/deserialization code (e.g. custom connectors, Hive ORC/Parquet readers, or page transport across Presto versions) producing misaligned offsets arrays; off-by-one errors when slicing key blocks.

Related errors


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