{"record":{"id":"5e1a8f2729719304","repo":"prestodb/presto","slug":"expected-value-to-contain-a-single-position-but-ha","errorCode":null,"errorMessage":"Expected value to contain a single position but has %s positions","messagePattern":"Expected value to contain a single position but has (.+?) positions","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java","lineNumber":55,"sourceCode":"    private static final int INSTANCE_SIZE = ClassLayout.parseClass(RunLengthEncodedBlock.class).instanceSize();\n\n    public static Block create(Type type, Object value, int positionCount)\n    {\n        Block block = Utils.nativeValueToBlock(type, value);\n        if (block instanceof RunLengthEncodedBlock) {\n            block = ((RunLengthEncodedBlock) block).getValue();\n        }\n        return new RunLengthEncodedBlock(block, positionCount);\n    }\n\n    private final Block value;\n    private final int positionCount;\n\n    public RunLengthEncodedBlock(Block value, int positionCount)\n    {\n        requireNonNull(value, \"value is null\");\n        if (value.getPositionCount() != 1) {\n            throw new IllegalArgumentException(format(\"Expected value to contain a single position but has %s positions\", value.getPositionCount()));\n        }\n\n        if (value instanceof RunLengthEncodedBlock) {\n            this.value = ((RunLengthEncodedBlock) value).getValue();\n        }\n        else {\n            this.value = value;\n        }\n\n        if (positionCount < 0) {\n            throw new IllegalArgumentException(\"positionCount is negative\");\n        }\n\n        this.positionCount = positionCount;\n    }\n\n    public Block getValue()\n    {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java#L37-L73","documentation":"RunLengthEncodedBlock represents N repetitions of exactly one value, so its constructor requires value.getPositionCount() == 1. Passing a multi-position block is a contract violation; the library throws IllegalArgumentException including the actual count, since it cannot pick which position to repeat.","triggerScenarios":"Passing any Block with positionCount != 1 to new RunLengthEncodedBlock(value, n) — e.g. passing a whole page block or an array block instead of a single-position block.","commonSituations":"Building constant columns for joins/aggregations where the constant was taken from a multi-row block; misusing getRegion/getPositionBlock results that return multi-position blocks; connector code synthesizing constant columns for predicate pushdown.","solutions":["Extract a single-position block first (e.g. value.getSingleValueBlock(0) or RunLengthEncodedBlock wrapping then unwrapping)","If you have a multi-position block, wrap each position separately or build via a page transform","Check value.getPositionCount() == 1 before constructing"],"exampleFix":"// before\nRunLengthEncodedBlock rle = new RunLengthEncodedBlock(valuesBlock, count); // valuesBlock has N positions\n// after\nRunLengthEncodedBlock rle = new RunLengthEncodedBlock(valuesBlock.getSingleValueBlock(0), count);","handlingStrategy":"validation","validationCode":"// before constructing an RLE block\nif (value.getPositionCount() != 1) {\n    throw new IllegalArgumentException(\"constant must be a single-position block, got \" + value.getPositionCount());\n}\nRunLengthEncodedBlock rle = new RunLengthEncodedBlock(value, n);\n","typeGuard":"boolean isSinglePositionBlock(Block b) {\n    return b.getPositionCount() == 1;\n}\n","tryCatchPattern":"try {\n    return new RunLengthEncodedBlock(value, n);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Expected value to contain a single position\")) {\n        return new RunLengthEncodedBlock(value.getSingleValueBlock(0), n);\n    }\n    throw e;\n}","preventionTips":["Use value.getSingleValueBlock(pos) to extract constants from multi-row blocks","Assert getPositionCount() == 1 when caching constant columns","Never pass whole page blocks as RLE values"],"tags":["presto","rle-block","argument-validation","blocks"],"backgroundTag":"block-single-position-required","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"}