prestodb/presto · error · PrestoException
INVALID_ARGUMENTS
INVALID_ARGUMENTS
Error message
Type %s does not allow ordering
What it means
The greater-than (>) operator specialized for DISTINCT types requires the underlying type to be orderable. In specialize, if the bound type variable T is a DistinctType whose base type cannot be ordered, Presto throws INVALID_ARGUMENTS with the type's display name. Ordering a non-orderable type is undefined, so the engine refuses to resolve the comparison operator.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/distinct/DistinctTypeGreaterThanOperator.java:58
extends SqlOperator
{
public static final DistinctTypeGreaterThanOperator DISTINCT_TYPE_GREATER_THAN_OPERATOR = new DistinctTypeGreaterThanOperator();
private DistinctTypeGreaterThanOperator()
{
super(GREATER_THAN,
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(GREATER_THAN, 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
- Cast to the base type for comparison: CAST(d1 AS baseType) > CAST(d2 AS baseType).
- Define or recreate the DISTINCT type over an orderable base type.
- Rewrite the comparison using explicit, well-defined criteria on the distinct type's fields.
- If equality-only semantics are needed, use = or DISTINCT FROM instead of ordering operators.
Example fix
// before SELECT * FROM t WHERE d_col > d_threshold; -- non-orderable distinct type // after SELECT * FROM t WHERE CAST(d_col AS bigint) > CAST(d_threshold AS bigint);
Defensive patterns
Strategy: type-guard
Validate before calling
-- guard > usage: only apply when the type supports ordering -- if (!distinctType.isOrderable()) rewrite comparison on base type
Type guard
boolean canOrder(DistinctType t) {
return t != null && t.isOrderable();
} Try / catch
try { rows = query("SELECT * FROM t WHERE d_col > d_threshold"); } catch (PrestoException e) { if (e.getErrorCode().getName().equals("INVALID_ARGUMENTS")) { rows = query("SELECT * FROM t WHERE CAST(d_col AS " + baseType + ") > CAST(d_threshold AS " + baseType + ")"); } else { throw e; } } Prevention
- Check isOrderable() of a DISTINCT type's base type before using >, >=, <, <= or ORDER BY on it.
- Cast to the base type for comparisons when orderability is not guaranteed.
- Keep distinct types over scalar orderable bases (bigint, varchar, double).
- Use = or IS DISTINCT FROM for equality-only distinct types.
When it happens
Trigger: Using d1 > d2 where d1/d2 have a DISTINCT type over a non-orderable base type (e.g. a distinct type over map/row with non-orderable members). Triggered during planning when the > operator is specialized for that type.
Common situations: Filtering or joining on distinct-typed columns whose base type lost orderability; schema migrations switching a distinct type's base type; ORDER BY/GROUP BY-adjacent comparisons on such columns.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/fe2f09dc79ef47af.
Report an issue: GitHub.