{"record":{"id":"c0fa46675e76f0cd","repo":"prestodb/presto","slug":"number-of-fields-in-rowblock-must-be-positive","errorCode":null,"errorMessage":"Number of fields in RowBlock must be positive","messagePattern":"Number of fields in RowBlock must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/AbstractRowBlock.java","lineNumber":58,"sourceCode":"\n    public abstract int getOffsetBase();\n\n    /**\n     * @return the underlying rowIsNull array, or null when all rows are guaranteed to be non-null\n     */\n    @Nullable\n    protected abstract boolean[] getRowIsNull();\n\n    // the offset in each field block, it can also be viewed as the \"entry-based\" offset in the RowBlock\n    protected final int getFieldBlockOffset(int position)\n    {\n        return getFieldBlockOffsets()[position + getOffsetBase()];\n    }\n\n    protected AbstractRowBlock(int numFields)\n    {\n        if (numFields <= 0) {\n            throw new IllegalArgumentException(\"Number of fields in RowBlock must be positive\");\n        }\n        this.numFields = numFields;\n    }\n\n    @Override\n    public String getEncodingName()\n    {\n        return RowBlockEncoding.NAME;\n    }\n\n    @Override\n    public final Block copyPositions(int[] positions, int offset, int length)\n    {\n        checkArrayRange(positions, offset, length);\n\n        int[] newOffsets = new int[length + 1];\n        int[] fieldBlockPositions = new int[length];\n        boolean[] newRowIsNull = null;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/AbstractRowBlock.java#L40-L76","documentation":"A RowBlock must have at least one field column; the AbstractRowBlock constructor rejects numFields <= 0 because a row type with zero fields cannot be represented in field blocks. This is a construction-time validation of the row type's arity.","triggerScenarios":"Constructing a row block (RowBlock.fromFieldBlocks, encoder/decoder paths) with a RowType that has zero fields, or passing an empty field-block array.","commonSituations":"Dynamically building a RowType from an empty schema or column list (e.g. a connector returning no columns); metadata/config errors where a row type is created before fields are known.","solutions":["Ensure the RowType has at least one field before constructing the corresponding row block.","Fix upstream metadata so empty schemas are rejected or given a placeholder field instead of becoming a zero-field row type.","Guard the code path: if fieldBlocks.length == 0, handle it before calling the block factory."],"exampleFix":"// before\nBlock[] fieldBlocks = collectFieldBlocks(rowType); // may be empty\nRowBlock block = RowBlock.fromFieldBlocks(0, new boolean[] {}, fieldBlocks);\n// after\ncheckState(!rowType.getFields().isEmpty(), \"row type must have at least one field\");\nBlock[] fieldBlocks = collectFieldBlocks(rowType);\nRowBlock block = RowBlock.fromFieldBlocks(0, new boolean[] {}, fieldBlocks);","handlingStrategy":"validation","validationCode":"if (fieldBlocks == null || fieldBlocks.length == 0) {\n    throw new IllegalStateException(\"cannot build a row block with zero fields\");\n}","typeGuard":"boolean hasFields(RowType rowType) {\n    return rowType != null && !rowType.getFields().isEmpty();\n}","tryCatchPattern":"try {\n    RowBlock block = RowBlock.fromFieldBlocks(positionCount, rowIsNull, fieldBlocks);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"must be positive\")) {\n        throw new SchemaException(\"row type has no fields\", e);\n    }\n    throw e;\n}","preventionTips":["Validate RowType arity at metadata load time, before blocks are produced.","Reject empty column lists at the connector/schema layer.","Add unit tests for dynamic row type construction."],"tags":["presto","block","row-block","illegal-argument"],"backgroundTag":"invalid-block-construction","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"}