{"record":{"id":"c7be9a076a6480be","repo":"prestodb/presto","slug":"expected-abstractsinglerowblock","errorCode":null,"errorMessage":"Expected AbstractSingleRowBlock","messagePattern":"Expected AbstractSingleRowBlock","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/RowBlockBuilder.java","lineNumber":270,"sourceCode":"        }\n        Block[] fieldBlocks = new Block[numFields];\n        for (int i = 0; i < numFields; i++) {\n            fieldBlocks[i] = fieldBlockBuilders[i].build();\n        }\n        return createRowBlockInternal(0, positionCount, hasNullRow ? rowIsNull : null, fieldBlockOffsets, fieldBlocks);\n    }\n\n    @Override\n    public String toString()\n    {\n        return format(\"RowBlockBuilder(%d){numFields=%d, positionCount=%d\", hashCode(), numFields, getPositionCount());\n    }\n\n    @Override\n    public BlockBuilder appendStructure(Block block)\n    {\n        if (!(block instanceof AbstractSingleRowBlock)) {\n            throw new IllegalStateException(\"Expected AbstractSingleRowBlock\");\n        }\n        if (currentEntryOpened) {\n            throw new IllegalStateException(\"Expected current entry to be closed but was opened\");\n        }\n        currentEntryOpened = true;\n\n        int blockPositionCount = block.getPositionCount();\n        if (blockPositionCount != numFields) {\n            throw new IllegalArgumentException(format(\"block position count (%s) is not equal to number of fields (%s)\", blockPositionCount, numFields));\n        }\n        for (int i = 0; i < blockPositionCount; i++) {\n            if (block.isNull(i)) {\n                fieldBlockBuilders[i].appendNull();\n            }\n            else {\n                block.writePositionTo(i, fieldBlockBuilders[i]);\n            }\n        }","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/RowBlockBuilder.java#L252-L288","documentation":"appendStructure(Block) copies an existing single-row block into this RowBlockBuilder. It only accepts AbstractSingleRowBlock instances (e.g. SingleRowBlock or RowBlock's single-position views); any other Block cannot be interpreted as one row of fields, so the library throws IllegalStateException instead of guessing the layout.","triggerScenarios":"Passing a non-row Block (e.g. an IntArrayBlock, a dictionary-encoded block, or a multi-position RowBlock) to RowBlockBuilder.appendStructure().","commonSituations":"Code appending values into row-typed columns that received a flattened or re-encoded block from an upstream operator (e.g. after exchange or lazy materialization changes the wrapper type).","solutions":["Ensure the argument is a single-position row block (check block instanceof AbstractSingleRowBlock before calling)","If the block is a multi-position row, iterate positions and copy fields per position","If data is in plain column blocks, build the row via beginBlockEntry/field writes instead of appendStructure","Unwrap known wrappers (RunLengthEncodedBlock, DictionaryBlock) to the underlying single row"],"exampleFix":"// before\nrowBuilder.appendStructure(valuesBlock); // valuesBlock is IntArrayBlock -> IllegalStateException\n// after\ncheckState(valuesBlock.getPositionCount() == 1 && valuesBlock instanceof AbstractSingleRowBlock);\nrowBuilder.appendStructure((AbstractSingleRowBlock) valuesBlock);","handlingStrategy":"type-guard","validationCode":"// before appendStructure\ncheckState(block instanceof AbstractSingleRowBlock,\n    \"appendStructure requires a single-row block, got %s\", block.getClass().getSimpleName());\ncheckState(block.getPositionCount() == 1 || block instanceof AbstractSingleRowBlock);\n","typeGuard":"boolean isSingleRowBlock(Block block) {\n    return block instanceof AbstractSingleRowBlock;\n}\n","tryCatchPattern":"try {\n    rowBuilder.appendStructure(block);\n} catch (IllegalStateException e) {\n    if (e.getMessage().equals(\"Expected AbstractSingleRowBlock\")) {\n        // fall back to field-by-field copy via beginBlockEntry\n        appendFieldsManually(rowBuilder, block);\n        return;\n    }\n    throw e;\n}","preventionTips":["Type-check with instanceof AbstractSingleRowBlock before calling appendStructure","Unwrap RunLengthEncodedBlock/DictionaryBlock wrappers first","For non-row or multi-position blocks use beginBlockEntry field writes instead"],"tags":["presto","row-block","type-mismatch","appendstructure"],"backgroundTag":"wrong-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"}