{"record":{"id":"277245d5c05edfa7","repo":"prestodb/presto","slug":"function-implementation-error-277245","errorCode":"FUNCTION_IMPLEMENTATION_ERROR","errorMessage":"Object is not a Block, but ","messagePattern":"Object is not a Block, but ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-accumulo/src/main/java/com/facebook/presto/accumulo/model/Field.java","lineNumber":392,"sourceCode":"\n    /**\n     * Does it's damnedest job to convert the given object to the given type.\n     *\n     * @param value Object to convert\n     * @param type Destination Presto type\n     * @return Null if null, the converted type of it could convert it, or the same value if it is fine just the way it is :D\n     * @throws PrestoException If the given object is not any flavor of the given type\n     */\n    private static Object cleanObject(Object value, Type type)\n    {\n        if (value == null) {\n            return null;\n        }\n\n        // Array? Better be a block!\n        if (Types.isArrayType(type)) {\n            if (!(value instanceof Block)) {\n                throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, \"Object is not a Block, but \" + value.getClass());\n            }\n            return value;\n        }\n\n        // Map? Better be a block!\n        if (Types.isMapType(type)) {\n            if (!(value instanceof Block)) {\n                throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, \"Object is not a Block, but \" + value.getClass());\n            }\n            return value;\n        }\n\n        // And now for the plain types\n        if (type.equals(BIGINT)) {\n            if (!(value instanceof Long)) {\n                throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, \"Object is not a Long, but \" + value.getClass());\n            }\n        }","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-accumulo/src/main/java/com/facebook/presto/accumulo/model/Field.java#L374-L410","documentation":"Field.cleanObject normalizes user-supplied Java objects into the representation the connector expects. For an ARRAY type, the value must be a Presto Block; passing any other object throws PrestoException FUNCTION_IMPLEMENTATION_ERROR including the actual class found. This signals a programming error in the caller, not a user-input problem.","triggerScenarios":"Constructing a Field with an ARRAY type while passing a value that is not a Presto Block — e.g., a java.util.List, Object[], or Iterator instead of the Block produced by the Presto block machinery.","commonSituations":"Custom connector code or tests building array fields from Java collections instead of Blocks; a conversion layer that forgot to call the block builder; upgrade where the internal representation changed from List to Block.","solutions":["Convert the Java collection to a Presto Block before constructing the Field (use a BlockBuilder for the element type and write each element).","If you already hold a Block, pass it directly — do not re-wrap it.","Inspect the exception message: it names the actual class (e.g., java.util.ArrayList) so you can find where the wrong object is created.","If migrating from an older connector version that used List, update the code to the Block-based API."],"exampleFix":"// before: passing a Java list for an array field\nField f = new Field(arrayType, Arrays.asList(1L, 2L));\n// after: build a Block\nBlockBuilder bb = BIGINT.createBlockBuilder(null, 2);\nBIGINT.writeLong(bb, 1L);\nBIGINT.writeLong(bb, 2L);\nField f = new Field(arrayType, bb.build());","handlingStrategy":"type-guard","validationCode":"// before constructing the Field\nif (Types.isArrayType(type) && !(value instanceof Block)) {\n    value = toArrayBlock((List<?>) value, elementType);\n}","typeGuard":"boolean isValidArrayValue(Type type, Object value) {\n    return !Types.isArrayType(type) || value instanceof Block;\n}","tryCatchPattern":null,"preventionTips":["Always build collection values with Presto BlockBuilders, never raw Java collections.","Centralize Field construction in one helper that performs the Block conversion.","When migrating connector versions, update any List-based array construction to Block."],"tags":["types","accumulo","block","programming-error"],"backgroundTag":"invalid-field-type","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"}