{"record":{"id":"e85814c3a2aedf5f","repo":"prestodb/presto","slug":"generic-user-error","errorCode":"GENERIC_USER_ERROR","errorMessage":"Function '%s' is missing from cache","messagePattern":"Function '(.+?)' is missing from cache","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonFileBasedFunctionNamespaceManager.java","lineNumber":100,"sourceCode":"        super(catalogName, sqlFunctionExecutors, config);\n        this.managerConfig = requireNonNull(managerConfig, \"managerConfig is null\");\n        this.functionDefinitionProvider = requireNonNull(functionDefinitionProvider, \"functionDefinitionProvider is null\");\n        bootstrapNamespaceFromFile();\n    }\n\n    @Override\n    public final AggregationFunctionImplementation getAggregateFunctionImplementation(FunctionHandle functionHandle, TypeManager typeManager)\n    {\n        checkCatalog(functionHandle);\n        checkArgument(functionHandle instanceof SqlFunctionHandle, \"Unsupported FunctionHandle type '%s'\", functionHandle.getClass().getSimpleName());\n\n        SqlFunctionHandle sqlFunctionHandle = (SqlFunctionHandle) functionHandle;\n\n        // Cache results if applicable\n        if (!aggregationImplementationByHandle.containsKey(sqlFunctionHandle)) {\n            SqlFunctionId functionId = sqlFunctionHandle.getFunctionId();\n            if (!latestFunctions.containsKey(functionId)) {\n                throw new PrestoException(GENERIC_USER_ERROR, format(\"Function '%s' is missing from cache\", functionId.getId()));\n            }\n\n            aggregationImplementationByHandle.put(\n                    sqlFunctionHandle,\n                    sqlInvokedFunctionToAggregationImplementation(latestFunctions.get(functionId), typeManager));\n        }\n\n        return aggregationImplementationByHandle.get(sqlFunctionHandle);\n    }\n\n    private static SqlInvokedFunction copyFunction(SqlInvokedFunction function)\n    {\n        return new SqlInvokedFunction(\n                function.getSignature().getName(),\n                function.getParameters(),\n                function.getSignature().getTypeVariableConstraints(),\n                function.getSignature().getLongVariableConstraints(),\n                function.getSignature().getReturnType(),","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonFileBasedFunctionNamespaceManager.java#L82-L118","documentation":"JsonFileBasedFunctionNamespaceManager resolves SQL-invoked aggregate function implementations from an in-memory cache keyed by SqlFunctionHandle. If the handle is absent from aggregationImplementationByHandle and the function id is not in latestFunctions, it throws GENERIC_USER_ERROR because the function metadata was never loaded (or was evicted/changed) from the JSON file.","triggerScenarios":"Calling getAggregateFunctionImplementation with a SqlFunctionHandle whose functionId is no longer (or never was) in latestFunctions — e.g. the JSON function file was reloaded/replaced after the handle was created, or the function was dropped.","commonSituations":"Cluster caches stale function handles after the JSON namespace file is edited out-of-band; a query plan references a function version that no longer exists; node started before the function file populated latestFunctions.","solutions":["Refresh/reload the function namespace so latestFunctions contains the function id, then re-run the query.","Re-create the missing SQL-invoked function (e.g. via a coordinator that supports createFunction against this manager).","Regenerate the query so it produces fresh SqlFunctionHandles matching the current function registry.","Check that the JSON file path config points at the file actually containing the function definitions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check the manager still knows the function before planning against it\nboolean known = manager.listFunctions(Optional.empty(), Optional.empty()).stream()\n    .anyMatch(f -> f.getFunctionId().getId().equals(expectedId));","typeGuard":null,"tryCatchPattern":"try {\n    impl = manager.getAggregateFunctionImplementation(handle);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == GENERIC_USER_ERROR.toErrorCode().getCode()) {\n        manager.loadInternalFunctions(); // refresh cache, then retry\n    } else { throw e; }\n}","preventionTips":["Reload the namespace after editing the JSON function file","Avoid holding function handles across namespace reloads","Ensure the JSON path config matches the actual function definitions file"],"tags":["sql-functions","cache","function-namespace"],"backgroundTag":"function-not-found","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"}