prestodb/presto · error · PrestoException
INVALID_ARGUMENTS
INVALID_ARGUMENTS
Error message
Type %s does not allow ordering
What it means
The less-than-or-equal operator for DISTINCT types demands an orderable distinct type. In specialize(), if the bound DistinctType's isOrderable() is false, Presto cannot resolve a LESS_THAN_OR_EQUAL operator on the base type and throws INVALID_ARGUMENTS. The base type must provide ordering for the distinct type to support <=.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/distinct/DistinctTypeLessThanOrEqualOperator.java:58
extends SqlOperator
{
public static final DistinctTypeLessThanOrEqualOperator DISTINCT_TYPE_LESS_THAN_OR_EQUAL_OPERATOR = new DistinctTypeLessThanOrEqualOperator();
private DistinctTypeLessThanOrEqualOperator()
{
super(LESS_THAN_OR_EQUAL,
ImmutableList.of(withVariadicBound("T", DISTINCT_TYPE)),
ImmutableList.of(),
parseTypeSignature(BOOLEAN),
ImmutableList.of(parseTypeSignature("T"), parseTypeSignature("T")));
}
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager)
{
DistinctType type = (DistinctType) boundVariables.getTypeVariable("T");
if (!type.isOrderable()) {
throw new PrestoException(INVALID_ARGUMENTS, format("Type %s does not allow ordering", type.getDisplayName()));
}
Type baseType = type.getBaseType();
FunctionHandle functionHandle = functionAndTypeManager.resolveOperator(LESS_THAN_OR_EQUAL, fromTypes(baseType, baseType));
return new BuiltInScalarFunctionImplementation(
false,
ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)),
functionAndTypeManager.getJavaScalarFunctionImplementation(functionHandle).getMethodHandle(),
Optional.empty());
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Ensure the distinct type's base type is orderable before using <=
- Replace ordering comparison with equality where semantics allow
- Cast operands to an orderable type before comparing
- Change the distinct type definition to wrap an orderable base type
Example fix
// before SELECT * FROM t WHERE x <= y; -- x,y distinct type, base not orderable // after SELECT * FROM t WHERE x = y; -- or compare casts of an orderable type
Defensive patterns
Strategy: validation
Validate before calling
if (!distinctType.isOrderable()) { throw new IllegalArgumentException("Type " + distinctType.getDisplayName() + " does not allow ordering; use equality instead"); } Type guard
if (type instanceof DistinctType && ((DistinctType) type).isOrderable()) { /* safe to use <= operator */ } Try / catch
try { return functionAndTypeManager.resolveOperator(LESS_THAN_OR_EQUAL, fromTypes(baseType, baseType)); } catch (PrestoException e) { if (e.getErrorCode().getCode() == INVALID_ARGUMENTS.toErrorCode().getCode()) { /* fall back to equality or cast-based compare */ } throw e; } Prevention
- Verify isOrderable() before emitting <= in query builders
- Declare distinct types only over orderable base types
- Replace range predicates with equality for non-orderable types
- Add schema-level checks that flag non-orderable distinct types used in range filters
When it happens
Trigger: Invoking the less_than_or_equal operator on a DISTINCT type whose underlying base type is not orderable; triggered inside specialize() when type variable 'T' fails the isOrderable() check.
Common situations: Using <= in range filters, BETWEEN-style predicates, or window functions on columns of a distinct type declared over a non-orderable base type.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/301858260eb2fdad.
Report an issue: GitHub.