prestodb/presto · error · IllegalArgumentException

Invalid array block:

Error message

Invalid array block: 

What it means

ColumnarArray.toColumnarArray converts a Block into a columnar (element-wise) view of an ARRAY-typed block. It only supports RunLengthEncodedBlock and AbstractArrayBlock subclasses; any other Block type cannot expose a raw element block, so the library throws IllegalArgumentException with the block's class name. This is an unsupported-block-type guard, typically meaning the block is not actually an ARRAY block.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/ColumnarArray.java:44

    private final int offsetsOffset;
    private final int[] offsets;
    private final Block elementsBlock;
    private final long retainedSizeInBytes;
    private final long estimatedSerializedSizeInBytes;

    public static ColumnarArray toColumnarArray(Block block)
    {
        requireNonNull(block, "block is null");

        if (block instanceof DictionaryBlock) {
            return toColumnarArray((DictionaryBlock) block);
        }
        if (block instanceof RunLengthEncodedBlock) {
            return toColumnarArray((RunLengthEncodedBlock) block);
        }

        if (!(block instanceof AbstractArrayBlock)) {
            throw new IllegalArgumentException("Invalid array block: " + block.getClass().getName());
        }

        AbstractArrayBlock arrayBlock = (AbstractArrayBlock) block;
        Block elementsBlock = arrayBlock.getRawElementBlock();

        // trim elements to just visible region
        int elementsOffset = 0;
        int elementsLength = 0;
        if (arrayBlock.getPositionCount() > 0) {
            elementsOffset = arrayBlock.getOffset(0);
            elementsLength = arrayBlock.getOffset(arrayBlock.getPositionCount()) - elementsOffset;
        }
        elementsBlock = elementsBlock.getRegion(elementsOffset, elementsLength);

        return new ColumnarArray(
                block,
                arrayBlock.getOffsetBase(),
                arrayBlock.getOffsets(),

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the block's type is the expected ARRAY type before calling toColumnarArray (e.g. via the associated Type)
  2. Ensure custom block implementations extend AbstractArrayBlock (and implement getRawElementBlock/getOffsets)
  3. Handle RunLengthEncodedBlock separately or rely on toColumnarArray's existing RLE overload
  4. Check upstream page producers/connectors for blocks mislabeled as array type

Example fix

// before
ColumnarArray arr = toColumnarArray(block); // throws for non-array block
// after
if (block instanceof AbstractArrayBlock || block instanceof RunLengthEncodedBlock) {
    ColumnarArray arr = toColumnarArray(block);
} else {
    throw new IllegalStateException("expected ARRAY block, got " + block.getClass().getName());
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(block instanceof AbstractArrayBlock) && !(block instanceof RunLengthEncodedBlock)) {
    throw new IllegalArgumentException("not an array block: " + block.getClass().getName());
}
ColumnarArray arr = ColumnarArray.toColumnarArray(block);

Type guard

boolean isArrayBlock(Block block) {
    return block instanceof AbstractArrayBlock || block instanceof RunLengthEncodedBlock;
}

Try / catch

try {
    ColumnarArray arr = ColumnarArray.toColumnarArray(block);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Invalid array block:")) {
        throw new IllegalStateException("block is not ARRAY-typed: " + e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Passing a non-array Block (e.g. ByteArrayBlock, LongArrayBlock, dictionary-wrapped block not extending AbstractArrayBlock) to toColumnarArray(Block) or ColumnarArray.columnarArray(Block); calling it on a block of the wrong SQL type due to a corrupted type mapping; a custom Block implementation that does not extend AbstractArrayBlock.

Common situations: Expression/optimizer code assuming a type that the page actually does not carry after a plan change; exchange/serialization bugs producing mislabeled blocks; third-party connectors returning custom block classes not extending AbstractArrayBlock.

Related errors


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