{"record":{"id":"35c3c5f163bea268","repo":"prestodb/presto","slug":"invalid-row-block","errorCode":null,"errorMessage":"Invalid row block: ","messagePattern":"Invalid row block: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/ColumnarRow.java","lineNumber":42,"sourceCode":"\n    private final Block nullCheckBlock;\n    private final Block[] fields;\n    private final long retainedSizeInBytes;\n    private final long estimatedSerializedSizeInBytes;\n\n    public static ColumnarRow toColumnarRow(Block block)\n    {\n        requireNonNull(block, \"block is null\");\n\n        if (block instanceof DictionaryBlock) {\n            return toColumnarRow((DictionaryBlock) block);\n        }\n        if (block instanceof RunLengthEncodedBlock) {\n            return toColumnarRow((RunLengthEncodedBlock) block);\n        }\n\n        if (!(block instanceof AbstractRowBlock)) {\n            throw new IllegalArgumentException(\"Invalid row block: \" + block.getClass().getName());\n        }\n\n        AbstractRowBlock rowBlock = (AbstractRowBlock) block;\n\n        // get fields for visible region\n        int firstRowPosition = rowBlock.getFieldBlockOffset(0);\n        int totalRowCount = rowBlock.getFieldBlockOffset(block.getPositionCount()) - firstRowPosition;\n        Block[] fieldBlocks = new Block[rowBlock.numFields];\n        for (int i = 0; i < fieldBlocks.length; i++) {\n            fieldBlocks[i] = rowBlock.getRawFieldBlocks()[i].getRegion(firstRowPosition, totalRowCount);\n        }\n\n        return new ColumnarRow(block, fieldBlocks, block.getRetainedSizeInBytes(), block.getSizeInBytes());\n    }\n\n    private static ColumnarRow toColumnarRow(DictionaryBlock dictionaryBlock)\n    {\n        // build a mapping from the old dictionary to a new dictionary with nulls removed","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/ColumnarRow.java#L24-L60","documentation":"ColumnarRow.toColumnarRow only supports row blocks extending AbstractRowBlock (plus RunLengthEncodedBlock). Any other Block implementation reaches a hard cast and would fail, so the method throws IllegalArgumentException with the block's class name. It guarantees the subsequent field access methods (getFieldBlockOffset, etc.) are valid.","triggerScenarios":"Calling ColumnarRow.toColumnarRow(block) or ColumnarRow.columnarRow(block) with a Block that is neither RunLengthEncodedBlock nor AbstractRowBlock — e.g. a ROW column encoded as dictionary or plain array block, or an unwrapped lazy block of the wrong concrete type.","commonSituations":"Connector/page deserialization bugs where a ROW column arrives as a different block class; forgetting to unwrap LazyBlock; passing an element block instead of the top-level row block; upgrading Presto where custom row block implementations were removed.","solutions":["Unwrap lazy blocks (block.getLoadedBlock() / LazyBlock.unwrap()) before converting","Confirm the page column's Type is RowType and its block is a row block before calling toColumnarRow","Make custom row Block implementations extend AbstractRowBlock","Read the exception message for the concrete class name and trace where that block is produced"],"exampleFix":"// before\nColumnarRow row = ColumnarRow.toColumnarRow(rawBlock);\n// after\nBlock block = rawBlock.getLoadedBlock();\ncheckArgument(block instanceof AbstractRowBlock || block instanceof RunLengthEncodedBlock, \"Expected row block, got %s\", block.getClass().getSimpleName());\nColumnarRow row = ColumnarRow.toColumnarRow(block);","handlingStrategy":"type-guard","validationCode":"public static ColumnarRow safeToColumnarRow(Block block)\n{\n    Block loaded = block.getLoadedBlock();\n    checkArgument(loaded instanceof AbstractRowBlock || loaded instanceof RunLengthEncodedBlock,\n        \"Expected row block, got %s\", loaded.getClass().getName());\n    return ColumnarRow.toColumnarRow(loaded);\n}","typeGuard":"static boolean isRowBlock(Block block) {\n    Block b = block.getLoadedBlock();\n    return b instanceof AbstractRowBlock || b instanceof RunLengthEncodedBlock;\n}","tryCatchPattern":"try {\n    ColumnarRow row = ColumnarRow.toColumnarRow(block);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Cannot convert column to row: \" + e.getMessage(), e);\n}","preventionTips":["Check the column Type is RowType before conversion","Unwrap lazy/dictionary-decorated blocks first","Pass the top-level row block, not a nested field block","Ensure custom row blocks extend AbstractRowBlock"],"tags":["block","row","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"}