{"record":{"id":"59479594f7c1f55d","repo":"prestodb/presto","slug":"type-must-be-a-decimaltype-for-decimalvector","errorCode":null,"errorMessage":"Type must be a DecimalType for DecimalVector","messagePattern":"Type must be a DecimalType for DecimalVector","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java","lineNumber":385,"sourceCode":"        }\n    }\n\n    public void assignBlockFromBigIntVector(BigIntVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                type.writeLong(builder, vector.get(i));\n            }\n        }\n    }\n\n    public void assignBlockFromDecimalVector(DecimalVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {\n        if (!(type instanceof DecimalType)) {\n            throw new IllegalArgumentException(\"Type must be a DecimalType for DecimalVector\");\n        }\n\n        DecimalType decimalType = (DecimalType) type;\n\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                BigDecimal decimal = vector.getObject(i); // Get the BigDecimal value\n                if (decimalType.isShort()) {\n                    builder.writeLong(decimal.unscaledValue().longValue());\n                }\n                else {\n                    Slice slice = Decimals.encodeScaledValue(decimal);\n                    decimalType.writeSlice(builder, slice, 0, slice.length());\n                }\n            }","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java#L367-L403","documentation":"assignBlockFromDecimalVector requires the Presto Type supplied alongside the Arrow DecimalVector to be a DecimalType, because it must write decimal values with matching precision/scale. If the Type is anything else, it throws IllegalArgumentException('Type must be a DecimalType for DecimalVector'). It indicates a mismatch between the Arrow vector's type and the declared Presto column type.","triggerScenarios":"Calling assignBlockFromValueVector (directly or via buildBlockFromFieldVector) with a DecimalVector while the mapped Presto Type is not DecimalType — e.g. it resolved to BIGINT, DOUBLE, or UNKNOWN due to a bad schema mapping.","commonSituations":"Connector type-mapping table maps an Arrow decimal column to the wrong Presto type; stale/incorrect column metadata from a catalog or schema registry; hand-written conversion code passing the wrong Type.","solutions":["Fix the type mapping so DECIMAL Arrow columns map to Presto DecimalType with matching precision/scale","Refresh or correct the schema metadata (connector table definition) so the declared type matches the Arrow data","If decimal precision/scale differs from expected, cast the column or adjust the DecimalType parameters","Verify the Type passed into assignBlockFromValueVector comes from the same schema as the Arrow vectors"],"exampleFix":"// before\nType type = BIGINT; // wrong mapping for DecimalVector\nbuilder.assignBlockFromDecimalVector(decimalVector, type, bb, 0, n);\n// after\nType type = DecimalType.createDecimalType(precision, scale);\nbuilder.assignBlockFromDecimalVector(decimalVector, type, bb, 0, n);","handlingStrategy":"validation","validationCode":"// verify declared Presto type matches the Arrow vector before building blocks\ncheckArgument(type instanceof DecimalType,\n    \"Column %s is DecimalVector but declared type is %s\", vector.getName(), type.getDisplayName());\ncheckArgument(((DecimalType) type).getPrecision() == vector.getField().getPrecision()\n    && ((DecimalType) type).getScale() == vector.getField().getScale(),\n    \"Decimal precision/scale mismatch for column %s\", vector.getName());","typeGuard":"boolean isCompatiblePrestoType(ValueVector v, Type t) {\n    if (v instanceof DecimalVector) {\n        return t instanceof DecimalType;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    blockBuilder.assignBlockFromDecimalVector(decimalVector, type, builder, 0, n);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"must be a DecimalType\")) {\n        throw new SchemaMismatchException(vector.getName(), type, \"DECIMAL\", e);\n    }\n    throw e;\n}","preventionTips":["Derive the Presto Type directly from the Arrow Field (getType(field)) instead of hardcoding","Keep the catalog's column metadata in sync with the Arrow schema","Validate precision and scale during schema mapping, not at read time"],"tags":["arrow","java","type-mismatch","decimal","illegal-argument"],"backgroundTag":"arrow-presto-type-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"}