{"record":{"id":"6fae6649806b59d6","repo":"prestodb/presto","slug":"duplicate-function-error","errorCode":"DUPLICATE_FUNCTION_ERROR","errorMessage":"Function '%s' already exists","messagePattern":"Function '(.+?)' already exists","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/functionNamespace/NativeFunctionNamespaceManager.java","lineNumber":249,"sourceCode":"\n    @Override\n    public final FunctionHandle getFunctionHandle(Optional<? extends FunctionNamespaceTransactionHandle> transactionHandle, Signature signature)\n    {\n        return new NativeFunctionHandle(signature);\n    }\n\n    @VisibleForTesting\n    public FunctionDefinitionProvider getFunctionDefinitionProvider()\n    {\n        return functionDefinitionProvider;\n    }\n\n    private synchronized void createFunction(SqlInvokedFunction function)\n    {\n        checkFunctionLanguageSupported(function);\n        SqlFunctionId functionId = function.getFunctionId();\n        if (functions.containsKey(function.getFunctionId())) {\n            throw new PrestoException(DUPLICATE_FUNCTION_ERROR, format(\"Function '%s' already exists\", functionId.getId()));\n        }\n\n        functions.put(functionId, function.withVersion(\"1\"));\n    }\n\n    private SqlInvokedFunction getSqlInvokedFunctionFromSignature(Signature signature)\n    {\n        try {\n            SqlFunction sqlFunction = specializedFunctionKeyCache.getUnchecked(signature).getFunction();\n            return (SqlInvokedFunction) sqlFunction;\n        }\n        catch (UncheckedExecutionException e) {\n            throw convertToPrestoException(e, format(\"Error getting FunctionMetadata for signature: %s\", signature));\n        }\n    }\n\n    private FunctionMetadata getMetadataFromNativeFunctionHandle(SqlFunctionHandle functionHandle)\n    {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/functionNamespace/NativeFunctionNamespaceManager.java#L231-L267","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Deduplicate the function definitions in the sidecar registry so each name+signature appears once.","Check which function source/bundle is providing the duplicate and remove the stale copy.","If intentional overloading is desired, differentiate the parameter types of the two definitions.","Restart/reload the namespace after fixing the registry so the memoized map is rebuilt cleanly."],"exampleFix":"// before: registry contains double_it(BIGINT) twice\n{\"name\":\"double_it\",\"signature\":\"(bigint)bigint\"}, {\"name\":\"double_it\",\"signature\":\"(bigint)bigint\"}\n// after\n{\"name\":\"double_it\",\"signature\":\"(bigint)bigint\"}","handlingStrategy":"validation","validationCode":"// dedupe definitions before loading\nSet<SqlFunctionId> seen = new HashSet<>();\nfor (SqlInvokedFunction f : suppliedFunctions) {\n    if (!seen.add(f.getFunctionId())) throw new IllegalStateException(\"Duplicate signature: \" + f.getFunctionId().getId());\n}","typeGuard":null,"tryCatchPattern":"try { manager.loadFunctions(defs); }\ncatch (PrestoException e) { if (\"DUPLICATE_FUNCTION_ERROR\".equals(e.getErrorCode().getName())) { log.error(\"Fix duplicate in sidecar registry: %s\", e.getMessage()); } throw e; }","preventionTips":["Enforce uniqueness of name+parameter-types in the sidecar function registry","Add a lint step in the function bundle build pipeline","Distinguish overloads by explicit differing parameter types"],"tags":["duplicate-function","function-namespace","registration","presto"],"backgroundTag":"duplicate-function-signature","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}