prestodb/presto · error · SemanticException
TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE
TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE
Error message
Returned relation type for table function %s is ambiguous
What it means
Analysis error for a table function: the return relation type is defined in two places at once (a statically declared return type plus a proper-columns descriptor from analyze(), or an ambiguous descriptor). The analyzer cannot decide which relation schema the function returns.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1900
.findFirst()
.ifPresent(input -> {
throw new SemanticException(TABLE_FUNCTION_IMPLEMENTATION_ERROR, "Table function %s does not specify required input columns from table argument %s", node.getName(), input);
});
}
private Descriptor verifyProperColumnsDescriptor(TableFunctionInvocation node, ConnectorTableFunction function, ReturnTypeSpecification returnTypeSpecification, Optional<Descriptor> analyzedProperColumnsDescriptor)
{
switch (returnTypeSpecification.getReturnType()) {
case "PASSTHROUGH":
if (analysis.isAliased(node)) {
// According to SQL standard ISO/IEC 9075-2, 7.6 <table reference>, p. 409,
// table alias is prohibited for a table function with ONLY PASS THROUGH returned type.
throw new SemanticException(TABLE_FUNCTION_INVALID_TABLE_FUNCTION_INVOCATION, node, "Alias specified for table function with ONLY PASS THROUGH return type");
}
if (analyzedProperColumnsDescriptor.isPresent()) {
// If a table function has ONLY PASS THROUGH returned type, it does not produce any proper columns,
// so the function's analyze() method should not return the proper columns descriptor.
throw new SemanticException(TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE, node, "Returned relation type for table function %s is ambiguous", node.getName());
}
if (function.getArguments().stream()
.filter(TableArgumentSpecification.class::isInstance)
.map(TableArgumentSpecification.class::cast)
.noneMatch(TableArgumentSpecification::isPassThroughColumns)) {
// According to SQL standard ISO/IEC 9075-2, 10.4 <routine invocation>, p. 764,
// if there is no generic table parameter that specifies PASS THROUGH, then number of proper columns shall be positive.
// For GENERIC_TABLE and DescribedTable returned types, this is enforced by the Descriptor constructor, which requires positive number of fields.
// Here we enforce it for the remaining returned type specification: ONLY_PASS_THROUGH.
throw new SemanticException(TABLE_FUNCTION_IMPLEMENTATION_ERROR, "A table function with ONLY_PASS_THROUGH return type must have a table argument with pass-through columns.");
}
return null;
case "GENERIC":
// According to SQL standard ISO/IEC 9075-2, 7.6 <table reference>, p. 409,
// table alias is mandatory for a polymorphic table function invocation which produces proper columns.
// We don't enforce this requirement.
return analyzedProperColumnsDescriptor
.orElseThrow(() -> new SemanticException(TABLE_FUNCTION_MISSING_RETURN_TYPE, node, "Cannot determine returned relation type for table function " + node.getName()));View on GitHub (pinned to 55bb57d202)
Solutions
- Provide the return type in exactly one way: either declare it statically or return the descriptor from analyze()
- Remove the redundant proper-columns specification from the invocation
- Align the declared columns with the table function metadata
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1900 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/527d39c2414ab95a.
Report an issue: GitHub.