prestodb/presto · error · IllegalStateException

Cannot create function in hive function namespace: %s

Error message

Cannot create function in hive function namespace: %s

What it means

HiveFunctionNamespaceManager backs the 'hive' function namespace, which is read-only: it only surfaces built-in Hive functions. createFunction unconditionally throws IllegalStateException for any function name, since SQL-invoked function creation is not supported in this namespace.

Source

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

    /**
     * this function namespace manager does not support transaction.
     */
    public FunctionNamespaceTransactionHandle beginTransaction()
    {
        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());
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Create the function in a writable function namespace (configure a persistent function namespace manager, e.g. JDBC/MySQL-backed) instead of 'hive'.
  2. Qualify the function with a catalog/schema bound to that writable namespace: CREATE FUNCTION mycat.default.my_fn(...).
  3. If the logic is needed globally, implement it as a Presto plugin (custom function) rather than a SQL-invoked function.
  4. Verify function-namespace-manager configuration in etc/function-namespace.properties to see which namespaces are read-only.

Example fix

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

Strategy: validation

Validate before calling

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

Try / catch

try {
    functionNamespaceManager.createFunction(fn, false);
} catch (IllegalStateException e) {
    // redirect creation to a writable namespace manager
}

Prevention

When it happens

Trigger: CREATE FUNCTION executed with a function name whose catalog/schema resolves to the hive function namespace, e.g. CREATE FUNCTION hive.default.my_fn(...) ...

Common situations: Users following SQL UDF tutorials without realizing built-in namespaces are read-only; creating functions in a catalog mapped to the hive function namespace instead of a persistent namespace (e.g., a JDBC-backed one).

Related errors


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