prestodb/presto · error · PrestoException

DUPLICATE_FUNCTION_ERROR

DUPLICATE_FUNCTION_ERROR

Error message

Function '%s' already exists

What it means

This duplicate-registration error comes from the private createFunction helper used when loading/memoizing functions inside NativeFunctionNamespaceManager: if the function ID (name + parameter types) already exists in the in-memory functions map, loading it again throws DUPLICATE_FUNCTION_ERROR. It indicates the same SQL invoked function signature was registered twice.

Source

Thrown at presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/functionNamespace/NativeFunctionNamespaceManager.java:249

    @Override
    public final FunctionHandle getFunctionHandle(Optional<? extends FunctionNamespaceTransactionHandle> transactionHandle, Signature signature)
    {
        return new NativeFunctionHandle(signature);
    }

    @VisibleForTesting
    public FunctionDefinitionProvider getFunctionDefinitionProvider()
    {
        return functionDefinitionProvider;
    }

    private synchronized void createFunction(SqlInvokedFunction function)
    {
        checkFunctionLanguageSupported(function);
        SqlFunctionId functionId = function.getFunctionId();
        if (functions.containsKey(function.getFunctionId())) {
            throw new PrestoException(DUPLICATE_FUNCTION_ERROR, format("Function '%s' already exists", functionId.getId()));
        }

        functions.put(functionId, function.withVersion("1"));
    }

    private SqlInvokedFunction getSqlInvokedFunctionFromSignature(Signature signature)
    {
        try {
            SqlFunction sqlFunction = specializedFunctionKeyCache.getUnchecked(signature).getFunction();
            return (SqlInvokedFunction) sqlFunction;
        }
        catch (UncheckedExecutionException e) {
            throw convertToPrestoException(e, format("Error getting FunctionMetadata for signature: %s", signature));
        }
    }

    private FunctionMetadata getMetadataFromNativeFunctionHandle(SqlFunctionHandle functionHandle)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Deduplicate the function definitions in the sidecar registry so each name+signature appears once.
  2. Check which function source/bundle is providing the duplicate and remove the stale copy.
  3. If intentional overloading is desired, differentiate the parameter types of the two definitions.
  4. Restart/reload the namespace after fixing the registry so the memoized map is rebuilt cleanly.

Example fix

// before: registry contains double_it(BIGINT) twice
{"name":"double_it","signature":"(bigint)bigint"}, {"name":"double_it","signature":"(bigint)bigint"}
// after
{"name":"double_it","signature":"(bigint)bigint"}
Defensive patterns

Strategy: validation

Validate before calling

// dedupe definitions before loading
Set<SqlFunctionId> seen = new HashSet<>();
for (SqlInvokedFunction f : suppliedFunctions) {
    if (!seen.add(f.getFunctionId())) throw new IllegalStateException("Duplicate signature: " + f.getFunctionId().getId());
}

Try / catch

try { manager.loadFunctions(defs); }
catch (PrestoException e) { if ("DUPLICATE_FUNCTION_ERROR".equals(e.getErrorCode().getName())) { log.error("Fix duplicate in sidecar registry: %s", e.getMessage()); } throw e; }

Prevention

When it happens

Trigger: Internal memoization path createFunction(SqlInvokedFunction) encountering a function whose SqlFunctionId already exists in the functions map — i.e. two function definitions with the same name and parameter types supplied to the manager.

Common situations: Sidecar function registry containing duplicate signatures for one catalog; duplicated function bundle entries; race where a synchronized reload sees a function already loaded; misconfigured multiple function sources feeding the same namespace.

Related errors


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