prestodb/presto · error · PrestoException
FUNCTION_NOT_FOUND
FUNCTION_NOT_FOUND
Error message
Sampling function: %s not cannot be resolved
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/optimizations/KeyBasedSampler.java:156
"CAST",
functionAndTypeManager.lookupCast(CAST, rowExpression.getType(), VARCHAR),
VARCHAR,
rowExpression);
}
else {
arg = rowExpression;
}
RowExpression sampledArg;
try {
sampledArg = call(
functionAndTypeManager,
getKeyBasedSamplingFunction(session),
DOUBLE,
ImmutableList.of(arg));
}
catch (PrestoException prestoException) {
throw new PrestoException(FUNCTION_NOT_FOUND, String.format("Sampling function: %s not cannot be resolved", getKeyBasedSamplingFunction(session)), prestoException);
}
RowExpression predicate = call(
LESS_THAN_OR_EQUAL.name(),
functionAndTypeManager.resolveOperator(OperatorType.LESS_THAN_OR_EQUAL, fromTypes(DOUBLE, DOUBLE)),
BOOLEAN,
sampledArg,
new ConstantExpression(arg.getSourceLocation(), getKeyBasedSamplingPercentage(session), DOUBLE));
FilterNode filterNode = new FilterNode(
tableScanNode.getSourceLocation(),
idAllocator.getNextId(),
tableScanNode,
predicate);
String tableName;
while (tableScanNode instanceof FilterNode || tableScanNode instanceof ProjectNode) {
tableScanNode = tableScanNode.getSources().get(0);View on GitHub (pinned to 55bb57d202)
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).
Example fix
// before SET SESSION key_based_sampling_function = 'sample_fn'; // after SET SESSION key_based_sampling_function = 'hive.default.key_sampling'; -- fully qualified, verified via SHOW FUNCTIONS
Defensive patterns
Strategy: validation
Validate before calling
-- run before the query SHOW SESSION LIKE '%key_based_sampling_function%'; SHOW FUNCTIONS LIKE '%<configured_fn>%'; -- confirm it resolves in the session's catalogs
Try / catch
try {
runQuery(sessionWithSampling);
} catch (PrestoException e) {
if (e.getErrorCode().getNameCode().name().equals("FUNCTION_NOT_FOUND")) {
// fall back to non-sampled query or reset the session property
resetSessionProperty("key_based_sampling_function");
runQuery(defaultSession);
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- INVALID_SESSION_PROPERTY
- HIVE_INVALID_METADATA
- INVALID_SESSION_PROPERTY
- GENERIC_INTERNAL_ERROR
- INVALID_SESSION_PROPERTY
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/79ba3037e5d87393.
Report an issue: GitHub.