{"record":{"id":"039f7cd3cbff1ff0","repo":"prestodb/presto","slug":"block-does-not-have-same-position-count","errorCode":null,"errorMessage":"Block does not have same position count","messagePattern":"Block does not have same position count","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/Page.java","lineNumber":206,"sourceCode":"        // Avoid creating new objects when region is same as original page\n        if (positionOffset == 0 && length == positionCount) {\n            return this;\n        }\n\n        // Create a new page view with the specified region\n        int channelCount = getChannelCount();\n        Block[] slicedBlocks = new Block[channelCount];\n        for (int i = 0; i < channelCount; i++) {\n            slicedBlocks[i] = blocks[i].getRegion(positionOffset, length);\n        }\n        return wrapBlocksWithoutCopy(length, slicedBlocks);\n    }\n\n    public Page appendColumn(Block block)\n    {\n        requireNonNull(block, \"block is null\");\n        if (positionCount != block.getPositionCount()) {\n            throw new IllegalArgumentException(\"Block does not have same position count\");\n        }\n\n        Block[] newBlocks = Arrays.copyOf(blocks, blocks.length + 1);\n        newBlocks[blocks.length] = block;\n        return wrapBlocksWithoutCopy(positionCount, newBlocks);\n    }\n\n    public Page compact()\n    {\n        if (getRetainedSizeInBytes() <= getSizeInBytes()) {\n            return this;\n        }\n\n        for (int i = 0; i < blocks.length; i++) {\n            Block block = blocks[i];\n            if (block instanceof DictionaryBlock) {\n                continue;\n            }","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/Page.java#L188-L224","documentation":"Page.appendColumn(block) adds a column to an existing page; it throws IllegalArgumentException when the new block's position count differs from the page's positionCount. All blocks in a Page must have the same number of positions (rows) — this enforces the rectangular invariant.","triggerScenarios":"Calling page.appendColumn(block) where block.getPositionCount() != page.getPositionCount(), e.g. appending a lookup/mask/hash block computed over a different number of rows, or appending a single-row constant block to a 1000-row page.","commonSituations":"Custom connectors or page processors joining blocks built from mismatched input sizes, hash/mask pages built against one batch then appended to another, or filter operators not accounting for reduced row counts after filtering.","solutions":["Ensure the appended block is built from the same rows: verify block.getPositionCount() == page.getPositionCount() before appending.","If sizes differ, slice the block with block.getRegion(0, page.getPositionCount()) or rebuild it for the current page batch.","Fix the upstream operator so the mask/hash column is computed per page batch, not reused across batches.","Add an assert or test comparing position counts before appendColumn in custom code."],"exampleFix":"// before\npage.appendColumn(hashBlockBuiltForPreviousBatch);\n// after\ncheckState(hashBlock.getPositionCount() == page.getPositionCount(), \"position count mismatch\");\npage.appendColumn(hashBlock);","handlingStrategy":"validation","validationCode":"boolean canAppendColumn(Page page, Block block) {\n    return page != null && block != null && page.getPositionCount() == block.getPositionCount();\n}","typeGuard":"Page safeAppendColumn(Page page, Block block) {\n    if (page == null || block == null || page.getPositionCount() != block.getPositionCount()) {\n        return null;\n    }\n    return page.appendColumn(block);\n}","tryCatchPattern":"try {\n    return page.appendColumn(block);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(format(\"Cannot append block of %d rows to page of %d rows\", block.getPositionCount(), page.getPositionCount()), e);\n}","preventionTips":["Build mask/hash/lookup columns per page batch, never reuse across batches.","Assert block.getPositionCount() == page.getPositionCount() in custom operators.","If blocks differ, slice or rebuild them before appending (block.getRegion).","Add connector/operator tests covering multi-batch input with varying row counts."],"tags":["page","block","position-count","presto-common"],"backgroundTag":"block-position-count-mismatch","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"}