{"record":{"id":"cd0808c8e32b0154","repo":"prestodb/presto","slug":"invalid-function-argument-cd0808","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Unsupported type: %s","messagePattern":"Unsupported type: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/util/JsonUtil.java","lineNumber":281,"sourceCode":"                    return (block, position) -> String.valueOf(type.getLong(block, position));\n                case StandardTypes.REAL:\n                    return (block, position) -> String.valueOf(intBitsToFloat((int) type.getLong(block, position)));\n                case StandardTypes.DOUBLE:\n                    return (block, position) -> String.valueOf(type.getDouble(block, position));\n                case StandardTypes.DECIMAL:\n                    DecimalType decimalType = (DecimalType) type;\n                    if (isShortDecimal(decimalType)) {\n                        return (block, position) -> Decimals.toString(decimalType.getLong(block, position), decimalType.getScale());\n                    }\n                    else {\n                        return (block, position) -> Decimals.toString(\n                                decodeUnscaledValue(type.getSlice(block, position)),\n                                decimalType.getScale());\n                    }\n                case StandardTypes.VARCHAR:\n                    return (block, position) -> type.getSlice(block, position).toStringUtf8();\n                default:\n                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Unsupported type: %s\", type));\n            }\n        }\n    }\n\n    // given block and position, write to JsonGenerator\n    public interface JsonGeneratorWriter\n    {\n        // write a Json value into the JsonGenerator, provided by block and position\n        void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, SqlFunctionProperties properties)\n                throws IOException;\n\n        static JsonGeneratorWriter createJsonGeneratorWriter(Type type)\n        {\n            TypeSignature signature = type.getTypeSignature();\n            if (signature.isDistinctType()) {\n                return createJsonGeneratorWriter(((DistinctType) type).getBaseType());\n            }\n            if (signature.isBigintEnum()) {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/util/JsonUtil.java#L263-L299","documentation":"JsonUtil's createObjectKeyProvider builds a function that extracts values from a Block as JSON object keys, and it only supports a fixed set of Presto types (e.g. VARCHAR, DECIMAL). If the column type passed in is anything outside that supported set, the default branch throws this PrestoException with INVALID_FUNCTION_ARGUMENT, embedding the unsupported type's string representation in the message.","triggerScenarios":"Calling createObjectKeyProvider with a Type that is not one of the explicitly handled cases in the switch — e.g. MAP, ARRAY, ROW, IPADDRESS, or a custom/plugin type — reaching the `default: throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Unsupported type: %s\", type))` branch.","commonSituations":"Running json_format or JSON-producing functions over columns of exotic types from connectors that expose non-standard types; a plugin introducing a custom Type that JsonUtil was never taught to serialize; schema drift after a table's column type changed to something the JSON path doesn't handle.","solutions":["Check the type named in the message; cast or convert the offending column to a JSON-supported type (e.g. CAST(col AS VARCHAR)) before the operation.","If the type should be supported, extend createObjectKeyProvider with a case for it in JsonUtil.java (or upgrade Presto to a version that handles it).","If the type comes from a connector/plugin, report or patch the plugin so it maps to a standard type for JSON paths."],"exampleFix":"// before\nSELECT json_format(CAST(row_col AS JSON)) FROM t; -- fails if inner field type unsupported\n// after\nSELECT json_format(CAST(CAST(row_col AS ROW(a VARCHAR)) AS JSON)) FROM t; -- normalize field types first","handlingStrategy":"validation","validationCode":"-- Validate column types are JSON-serializable before running\nSELECT data_type\nFROM information_schema.columns\nWHERE table_name = 't' AND column_name = 'col';\n-- ensure data_type is one of: boolean, tinyint, smallint, integer, bigint, real, double, decimal, varchar, date, timestamp, array, map, row","typeGuard":"boolean isJsonSafeType(Type type) {\n    return type instanceof BooleanType || type instanceof BigintType || type instanceof VarcharType\n        || type instanceof DecimalType || type instanceof RowType || type instanceof ArrayType || type instanceof MapType;\n}","tryCatchPattern":"try {\n    result = query;\n} catch (PrestoException e) {\n    if (e.getErrorCode() == StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode().getCode()\n            && e.getMessage().startsWith(\"Unsupported type:\")) {\n        // fall back to casting unsupported columns to VARCHAR\n    } else { throw e; }\n}","preventionTips":["Audit column types for JSON-producing queries; exclude or CAST exotic types (IPADDRESS, HyperLogLog, JSON, custom plugin types).","After connector/schema changes, re-check that serialized columns still use standard types.","Prefer explicit CAST(... AS VARCHAR/JSON) over relying on implicit type support."],"tags":["json","invalid-function-argument","unsupported-type","presto"],"backgroundTag":"json-unsupported-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"}