{"record":{"id":"79ba3037e5d87393","repo":"prestodb/presto","slug":"function-not-found-79ba30","errorCode":"FUNCTION_NOT_FOUND","errorMessage":"Sampling function: %s not cannot be resolved","messagePattern":"Sampling function: (.+?) not cannot be resolved","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/optimizations/KeyBasedSampler.java","lineNumber":156,"sourceCode":"                        \"CAST\",\n                        functionAndTypeManager.lookupCast(CAST, rowExpression.getType(), VARCHAR),\n                        VARCHAR,\n                        rowExpression);\n            }\n            else {\n                arg = rowExpression;\n            }\n\n            RowExpression sampledArg;\n            try {\n                sampledArg = call(\n                        functionAndTypeManager,\n                        getKeyBasedSamplingFunction(session),\n                        DOUBLE,\n                        ImmutableList.of(arg));\n            }\n            catch (PrestoException prestoException) {\n                throw new PrestoException(FUNCTION_NOT_FOUND, String.format(\"Sampling function: %s not cannot be resolved\", getKeyBasedSamplingFunction(session)), prestoException);\n            }\n\n            RowExpression predicate = call(\n                    LESS_THAN_OR_EQUAL.name(),\n                    functionAndTypeManager.resolveOperator(OperatorType.LESS_THAN_OR_EQUAL, fromTypes(DOUBLE, DOUBLE)),\n                    BOOLEAN,\n                    sampledArg,\n                    new ConstantExpression(arg.getSourceLocation(), getKeyBasedSamplingPercentage(session), DOUBLE));\n\n            FilterNode filterNode = new FilterNode(\n                    tableScanNode.getSourceLocation(),\n                    idAllocator.getNextId(),\n                    tableScanNode,\n                    predicate);\n\n            String tableName;\n            while (tableScanNode instanceof FilterNode || tableScanNode instanceof ProjectNode) {\n                tableScanNode = tableScanNode.getSources().get(0);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/optimizations/KeyBasedSampler.java#L138-L174","documentation":"KeyBasedSampler injects a key-based sampling predicate into the plan by resolving a user-configured sampling function (session property key_based_sampling_function) via the function-and-type manager. When the function name from the session cannot be resolved to a catalog function, the planner wraps the resolution failure in FUNCTION_NOT_FOUND. It means the configured sampling function does not exist in any catalog visible to the session.","triggerScenarios":"Running a query on a table whose sampling is configured for key-based sampling while session property key_based_sampling_function names a function that does not exist, is misspelled, is not in the right schema, or has an incompatible signature (needs to accept the DOUBLE argument and be usable in the constructed call).","commonSituations":"Typo in the session property value; function defined only in a catalog not in the session's search path; upgrading Presto where the built-in sampling function was renamed or removed; passing a qualified name for a function that lives in a different catalog.","solutions":["Check the session property value: SHOW SESSION LIKE '%key_based_sampling%' or inspect the query's session properties, and correct the function name.","Verify the function exists with SHOW FUNCTIONS and qualify it with its full catalog.schema.name in the session property.","Ensure the function signature matches what the sampler builds (a single DOUBLE argument compatible with the sampling call).","If key-based sampling is not needed, unset the session property (RESET SESSION key_based_sampling_function)."],"exampleFix":"// before\nSET SESSION key_based_sampling_function = 'sample_fn';\n// after\nSET SESSION key_based_sampling_function = 'hive.default.key_sampling'; -- fully qualified, verified via SHOW FUNCTIONS","handlingStrategy":"validation","validationCode":"-- run before the query\nSHOW SESSION LIKE '%key_based_sampling_function%';\nSHOW FUNCTIONS LIKE '%<configured_fn>%'; -- confirm it resolves in the session's catalogs","typeGuard":null,"tryCatchPattern":"try {\n    runQuery(sessionWithSampling);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getNameCode().name().equals(\"FUNCTION_NOT_FOUND\")) {\n        // fall back to non-sampled query or reset the session property\n        resetSessionProperty(\"key_based_sampling_function\");\n        runQuery(defaultSession);\n    } else throw e;\n}","preventionTips":["Always qualify the sampling function with catalog.schema.name in the session property","Verify with SHOW FUNCTIONS after changing catalogs or upgrading Presto","Reset the property when key-based sampling is not needed for the session"],"tags":["planner","function-resolution","session-property","sampling"],"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"}