prestodb/presto · error · IllegalStateException

Cannot alter function in hive function namespace: %s

Error message

Cannot alter function in hive function namespace: %s

What it means

alterFunction in HiveFunctionNamespaceManager throws IllegalStateException for every call: the hive function namespace is read-only and supports neither CREATE, ALTER, nor DROP of SQL-invoked functions. The error names the function so the caller knows which definition was targeted.

Source

Thrown at presto-hive-function-namespace/src/main/java/com/facebook/presto/hive/functions/HiveFunctionNamespaceManager.java:125

        return new EmptyTransactionHandle();
    }

    public void commit(FunctionNamespaceTransactionHandle transactionHandle)
    {
    }

    public void abort(FunctionNamespaceTransactionHandle transactionHandle)
    {
    }

    public void createFunction(SqlInvokedFunction function, boolean replace)
    {
        throw new IllegalStateException(format("Cannot create function in hive function namespace: %s", function.getSignature().getName()));
    }

    public void alterFunction(QualifiedObjectName functionName, Optional<List<TypeSignature>> parameterTypes, AlterRoutineCharacteristics alterRoutineCharacteristics)
    {
        throw new IllegalStateException(format("Cannot alter function in hive function namespace: %s", functionName));
    }

    public void dropFunction(QualifiedObjectName functionName, Optional<List<TypeSignature>> parameterTypes, boolean exists)
    {
        throw new IllegalStateException(format("Cannot drop function in hive function namespace: %s", functionName));
    }

    @Override
    public Collection<HiveFunction> listFunctions(Optional<String> likePattern, Optional<String> escape)
    {
        return getCurrentFunctionNames().stream().map(functionName -> createDummyHiveFunction(functionName)).collect(toImmutableList());
    }

    public Collection<HiveFunction> getFunctions(Optional<? extends FunctionNamespaceTransactionHandle> transactionHandle, QualifiedObjectName functionName)
    {
        throw new IllegalStateException("Get function is not supported");
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Alter the function in a writable (persistent) function namespace; the built-in hive namespace cannot store user functions.
  2. Fully qualify the function with a catalog mapped to the persistent namespace manager.
  3. If the function truly lives in hive namespace, it is built-in — you cannot modify it; define your own under a different name/namespace.
  4. Check the function-namespace configuration to confirm which manager owns the target catalog.

Example fix

// before
ALTER FUNCTION hive.default.my_add(a integer, b integer) ...
// after
ALTER FUNCTION mycat.default.my_add(a integer, b integer) ...
Defensive patterns

Strategy: validation

Validate before calling

if (functionName.getCatalogName().equalsIgnoreCase("hive")) {
    throw new UnsupportedOperationException(
        "cannot ALTER FUNCTION in read-only hive namespace; use a persistent namespace catalog");
}

Try / catch

try {
    manager.alterFunction(name, paramTypes, characteristics);
} catch (IllegalStateException e) {
    // recreate the function in a writable namespace instead
}

Prevention

When it happens

Trigger: ALTER FUNCTION <name> (or alterFunction via the FunctionAndTypeManager) where the function's namespace resolves to the hive namespace manager.

Common situations: Trying to change a characteristic (SECURITY, COMMENT, signature) of a function registered in the built-in hive namespace; scripts that assumed all namespaces are mutable.

Related errors


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