{"record":{"id":"0aeeabed12903f08","repo":"prestodb/presto","slug":"column-does-not-have-same-position-count-s-as-p","errorCode":null,"errorMessage":"Column does not have same position count (%s) as page (%s)","messagePattern":"Column does not have same position count \\((.+?)\\) as page \\((.+?)\\)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/Page.java","lineNumber":422,"sourceCode":"    {\n        return wrapBlocksWithoutCopy(positionCount, new Block[] {this.blocks[channel]});\n    }\n\n    public Page extractChannels(int[] channels)\n    {\n        requireNonNull(channels, \"channels is null\");\n\n        Block[] blocks = new Block[channels.length];\n        for (int i = 0; i < channels.length; i++) {\n            blocks[i] = this.blocks[channels[i]];\n        }\n        return wrapBlocksWithoutCopy(positionCount, blocks);\n    }\n\n    public Page prependColumn(Block column)\n    {\n        if (column.getPositionCount() != positionCount) {\n            throw new IllegalArgumentException(String.format(\"Column does not have same position count (%s) as page (%s)\", column.getPositionCount(), positionCount));\n        }\n\n        Block[] result = new Block[blocks.length + 1];\n        result[0] = column;\n        System.arraycopy(blocks, 0, result, 1, blocks.length);\n\n        return wrapBlocksWithoutCopy(positionCount, result);\n    }\n\n    public Page dropColumn(int channelIndex)\n    {\n        if (channelIndex < 0 || channelIndex >= getChannelCount()) {\n            throw new IndexOutOfBoundsException(format(\"Invalid channel %d in page with %s channels\", channelIndex, getChannelCount()));\n        }\n\n        Block[] result = new Block[getChannelCount() - 1];\n        System.arraycopy(blocks, 0, result, 0, channelIndex);\n        System.arraycopy(blocks, channelIndex + 1, result, channelIndex, getChannelCount() - channelIndex - 1);","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/Page.java#L404-L440","documentation":"Page.prependColumn adds a Block as the first channel of the page; all channels in a Page must have the same number of positions. If the new column's position count differs from the page's positionCount, the resulting Page would be malformed, so the library throws IllegalArgumentException.","triggerScenarios":"Calling page.prependColumn(block) where block.getPositionCount() != page.getPositionCount() — e.g. prepending row-number or group-id columns computed over a different number of rows.","commonSituations":"Operators like MarkDistinct/Window that build group id or row id columns; test code (testPrependColumnWrongNumberOfRows) constructing mismatched blocks; bugs where a filter earlier reduced page rows but not the new column.","solutions":["Recompute the column so it has exactly page.getPositionCount() positions before prepending","If the page was filtered, filter/rebuild the column with the same retainedPositions before prepending","Sanity-check the order of operations: prepend before filtering, or apply the same mask to both"],"exampleFix":"// before\nPage filtered = page.getPositions(retained, 0, retained.length);\nfiltered.prependColumn(rowIds); // rowIds sized for original page -> throws\n// after\nBlock sizedRowIds = rowIds.getPositions(retained, 0, retained.length);\nfiltered.prependColumn(sizedRowIds);","handlingStrategy":"validation","validationCode":"if (column.getPositionCount() != page.getPositionCount()) {\n    throw new IllegalArgumentException(\"column rows \" + column.getPositionCount()\n        + \" != page rows \" + page.getPositionCount());\n}\nPage result = page.prependColumn(column);","typeGuard":"boolean canPrepend(Page page, Block column) {\n    return column.getPositionCount() == page.getPositionCount();\n}","tryCatchPattern":"try {\n    page = page.prependColumn(column);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().startsWith(\"Column does not have same position count\")) throw e;\n    column = column.getPositions(retainedPositions, 0, retainedPositions.length);\n    page = page.prependColumn(column);\n}","preventionTips":["Apply the same position filter to every block added to a page","Prepend columns before filtering, or remap both consistently","Add position-count assertions in operator tests"],"tags":["presto","page","position-count-mismatch","illegal-argument"],"backgroundTag":"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"}