{"record":{"id":"86edda50909c53f3","repo":"prestodb/presto","slug":"invalid-map-block","errorCode":null,"errorMessage":"Invalid map block: ","messagePattern":"Invalid map block: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/ColumnarMap.java","lineNumber":47,"sourceCode":"    private final Block keysBlock;\n    private final Block valuesBlock;\n    private final int[] hashTables;\n    private final long retainedSizeInBytes;\n    private final long estimatedSerializedSizeInBytes;\n\n    public static ColumnarMap toColumnarMap(Block block)\n    {\n        requireNonNull(block, \"block is null\");\n\n        if (block instanceof DictionaryBlock) {\n            return toColumnarMap((DictionaryBlock) block);\n        }\n        if (block instanceof RunLengthEncodedBlock) {\n            return toColumnarMap((RunLengthEncodedBlock) block);\n        }\n\n        if (!(block instanceof AbstractMapBlock)) {\n            throw new IllegalArgumentException(\"Invalid map block: \" + block.getClass().getName());\n        }\n\n        AbstractMapBlock mapBlock = (AbstractMapBlock) block;\n\n        int offsetBase = mapBlock.getOffsetBase();\n        int[] offsets = mapBlock.getOffsets();\n\n        // get the keys and values for visible region\n        int firstEntryPosition = mapBlock.getOffset(0);\n        int totalEntryCount = mapBlock.getOffset(block.getPositionCount()) - firstEntryPosition;\n        Block keysBlock = mapBlock.getRawKeyBlock().getRegion(firstEntryPosition, totalEntryCount);\n        Block valuesBlock = mapBlock.getRawValueBlock().getRegion(firstEntryPosition, totalEntryCount);\n        int[] hashTables = mapBlock.getHashTables().get();\n\n        return new ColumnarMap(\n                block,\n                offsetBase,\n                offsets,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/ColumnarMap.java#L29-L65","documentation":"ColumnarMap.toColumnarMap only understands map blocks that extend AbstractMapBlock (plus RunLengthEncodedBlock). When handed a Block of any other concrete type (e.g. a plain BlockBuilder output, IntArrayBlock, or a decoded/lazy block that was not yet compaction into a map representation), it throws IllegalArgumentException with the offending class name appended. This is a defensive type check because the method casts the block to AbstractMapBlock immediately afterwards.","triggerScenarios":"Calling ColumnarMap.toColumnarMap(block) or ColumnarMap.columnarMap(block) with a Block that is neither a RunLengthEncodedBlock nor an AbstractMapBlock — e.g. passing the wrong-typed column of a page, a block produced by a non-map writer, or an unwrapped lazy block.","commonSituations":"Page/column type mismatches in custom connectors or readers (e.g. ORC/Parquet readers that decode a MAP column into the wrong block class); skipping the LazyBlock.unwrap call before extracting columns; version changes where a custom Block implementation no longer extends AbstractMapBlock.","solutions":["Verify the Block being passed is actually a MAP-typed column (check the Type of the page column before converting)","Call LazyBlock.unwrap() on the block (or Page.getBlock) before invoking toColumnarMap so lazy/dictionary-decorated blocks resolve to the real AbstractMapBlock","Ensure custom Block implementations for maps extend AbstractMapBlock","Check the exception message for the actual class name of the block and fix the upstream code producing that block"],"exampleFix":"// before\nBlock block = page.getBlock(1);\nColumnarMap map = ColumnarMap.toColumnarMap(block); // throws if lazy/unwrapped\n// after\nBlock block = page.getBlock(1).getLoadedBlock();\ncheckArgument(block instanceof AbstractMapBlock || block instanceof RunLengthEncodedBlock, \"Expected map block, got %s\", block.getClass().getSimpleName());\nColumnarMap map = ColumnarMap.toColumnarMap(block);","handlingStrategy":"type-guard","validationCode":"public static ColumnarMap safeToColumnarMap(Block block)\n{\n    Block loaded = block.getLoadedBlock();\n    checkArgument(loaded instanceof AbstractMapBlock || loaded instanceof RunLengthEncodedBlock,\n        \"Expected map block, got %s\", loaded.getClass().getName());\n    return ColumnarMap.toColumnarMap(loaded);\n}","typeGuard":"static boolean isMapBlock(Block block) {\n    Block b = block.getLoadedBlock();\n    return b instanceof AbstractMapBlock || b instanceof RunLengthEncodedBlock;\n}","tryCatchPattern":"try {\n    ColumnarMap map = ColumnarMap.toColumnarMap(block);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Cannot convert column to map: \" + e.getMessage(), e);\n}","preventionTips":["Always check the column Type is MapType before calling toColumnarMap","Unwrap LazyBlocks (getLoadedBlock) before block-type checks","Keep custom map Block implementations extending AbstractMapBlock","Log block.getClass().getName() in connector code to catch producer bugs early"],"tags":["block","map","type-mismatch","presto"],"backgroundTag":"invalid-block-type","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"}