prestodb/presto · error · IllegalStateException

Cannot drop function in hive function namespace: %s

Error message

Cannot drop function in hive function namespace: %s

What it means

dropFunction in HiveFunctionNamespaceManager throws IllegalStateException unconditionally: the read-only hive function namespace never contains user-created SQL functions, so DROP FUNCTION against it is always rejected. This protects the built-in Hive function registry.

Source

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

    }

    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");
    }

    public FunctionHandle getFunctionHandle(Optional<? extends FunctionNamespaceTransactionHandle> transactionHandle, Signature signature)
    {
        throw new IllegalStateException("Get function handle is not supported");
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Drop the function from the writable namespace where it was actually created (fully qualify with that catalog/schema).
  2. Built-in hive functions cannot be dropped — if a built-in shadows your UDF, rename your function or adjust search path ordering.
  3. List available functions in the namespace (SHOW FUNCTIONS) to confirm which are user-defined vs built-in.
  4. Configure and use a persistent function namespace manager for user-defined SQL functions.

Example fix

// before
DROP FUNCTION hive.default.my_add(integer, integer);
// after
DROP FUNCTION mycat.default.my_add(integer, integer);
Defensive patterns

Strategy: validation

Validate before calling

if (functionName.getCatalogName().equalsIgnoreCase("hive")) {
    throw new UnsupportedOperationException(
        "cannot DROP FUNCTION in read-only hive namespace; built-in functions cannot be removed");
}

Try / catch

try {
    manager.dropFunction(name, paramTypes, false);
} catch (IllegalStateException e) {
    // ignore if cleanup script; or target the correct writable namespace
}

Prevention

When it happens

Trigger: DROP FUNCTION <name> where the function name resolves to the hive function namespace manager.

Common situations: Cleanup scripts dropping functions that were mistakenly created in a read-only namespace; attempting to 'remove' a built-in Hive function that shadows a user function.

Related errors


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