{"record":{"id":"48915717140e4c72","repo":"prestodb/presto","slug":"block-position-count-s-is-not-equal-to-number-o","errorCode":null,"errorMessage":"block position count (%s) is not equal to number of fields (%s)","messagePattern":"block position count \\((.+?)\\) is not equal to number of fields \\((.+?)\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/RowBlockBuilder.java","lineNumber":279,"sourceCode":"    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        }\n\n        closeEntry();\n        return this;\n    }\n\n    @Override\n    public BlockBuilder appendStructureInternal(Block block, int position)\n    {\n        if (!(block instanceof AbstractRowBlock)) {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/RowBlockBuilder.java#L261-L297","documentation":"appendStructure copies a single-row block field-by-field into the builder, so the incoming block's position count must equal the builder's declared number of fields (numFields). A mismatch means the block's layout cannot map onto the row type, so the library throws IllegalArgumentException with both counts.","triggerScenarios":"Passing a single-row block built from a different row type (different arity) to appendStructure, e.g. appending a 3-field row into a 2-field row builder after a schema/type change.","commonSituations":"Schema evolution where a row type gained/lost fields but upstream blocks were built with the old type; dynamic row types whose field count differs across connectors or catalog versions.","solutions":["Verify block.getPositionCount() equals the row type's field count before appending","Ensure the RowType/TypeSignature used to create the builder matches the block's row type","Rebuild the block with the current row type if the schema changed","Use row field mapping/translation code for schema evolution instead of direct append"],"exampleFix":"// before\n// builder created for RowType(a, b); block has 3 fields\nrowBuilder.appendStructure(block); // IllegalArgumentException: 3 != 2\n// after\ncheckArgument(block.getPositionCount() == rowBuilder.getNumFields(), \"row arity mismatch\");\nrowBuilder.appendStructure(block);","handlingStrategy":"validation","validationCode":"// before appendStructure, verify arity matches the builder's row type\nif (block.getPositionCount() != expectedNumFields) {\n    throw new IllegalArgumentException(format(\n        \"row arity mismatch: block has %s fields, builder expects %s\",\n        block.getPositionCount(), expectedNumFields));\n}\n","typeGuard":null,"tryCatchPattern":"try {\n    rowBuilder.appendStructure(block);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is not equal to number of fields\")) {\n        // rebuild the row with the expected type rather than appending directly\n        throw new IllegalStateException(\"row type of block does not match builder type; remap fields\", e);\n    }\n    throw e;\n}","preventionTips":["Compare block.getPositionCount() with the row type's field count before appending","Keep row TypeSignature and builder construction from the same Type object","Handle schema evolution explicitly instead of reusing old blocks","Add arity assertions in serialization tests"],"tags":["presto","row-block","arity-mismatch","type-mismatch"],"backgroundTag":"schema-arity-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"}