prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Unsupported type: %s

What it means

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.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/util/JsonUtil.java:281

                    return (block, position) -> String.valueOf(type.getLong(block, position));
                case StandardTypes.REAL:
                    return (block, position) -> String.valueOf(intBitsToFloat((int) type.getLong(block, position)));
                case StandardTypes.DOUBLE:
                    return (block, position) -> String.valueOf(type.getDouble(block, position));
                case StandardTypes.DECIMAL:
                    DecimalType decimalType = (DecimalType) type;
                    if (isShortDecimal(decimalType)) {
                        return (block, position) -> Decimals.toString(decimalType.getLong(block, position), decimalType.getScale());
                    }
                    else {
                        return (block, position) -> Decimals.toString(
                                decodeUnscaledValue(type.getSlice(block, position)),
                                decimalType.getScale());
                    }
                case StandardTypes.VARCHAR:
                    return (block, position) -> type.getSlice(block, position).toStringUtf8();
                default:
                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unsupported type: %s", type));
            }
        }
    }

    // given block and position, write to JsonGenerator
    public interface JsonGeneratorWriter
    {
        // write a Json value into the JsonGenerator, provided by block and position
        void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, SqlFunctionProperties properties)
                throws IOException;

        static JsonGeneratorWriter createJsonGeneratorWriter(Type type)
        {
            TypeSignature signature = type.getTypeSignature();
            if (signature.isDistinctType()) {
                return createJsonGeneratorWriter(((DistinctType) type).getBaseType());
            }
            if (signature.isBigintEnum()) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. 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.
  2. 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).
  3. If the type comes from a connector/plugin, report or patch the plugin so it maps to a standard type for JSON paths.

Example fix

// before
SELECT json_format(CAST(row_col AS JSON)) FROM t; -- fails if inner field type unsupported
// after
SELECT json_format(CAST(CAST(row_col AS ROW(a VARCHAR)) AS JSON)) FROM t; -- normalize field types first
Defensive patterns

Strategy: validation

Validate before calling

-- Validate column types are JSON-serializable before running
SELECT data_type
FROM information_schema.columns
WHERE table_name = 't' AND column_name = 'col';
-- ensure data_type is one of: boolean, tinyint, smallint, integer, bigint, real, double, decimal, varchar, date, timestamp, array, map, row

Type guard

boolean isJsonSafeType(Type type) {
    return type instanceof BooleanType || type instanceof BigintType || type instanceof VarcharType
        || type instanceof DecimalType || type instanceof RowType || type instanceof ArrayType || type instanceof MapType;
}

Try / catch

try {
    result = query;
} catch (PrestoException e) {
    if (e.getErrorCode() == StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode().getCode()
            && e.getMessage().startsWith("Unsupported type:")) {
        // fall back to casting unsupported columns to VARCHAR
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/cd0808c8e32b0154. Report an issue: GitHub.