{"record":{"id":"28a53a3997d3e831","repo":"prestodb/presto","slug":"invalid-arguments-28a53a","errorCode":"INVALID_ARGUMENTS","errorMessage":"Type %s does not allow ordering","messagePattern":"Type (.+?) does not allow ordering","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/distinct/DistinctTypeLessThanOperator.java","lineNumber":60,"sourceCode":"    public static final DistinctTypeLessThanOperator DISTINCT_TYPE_LESS_THAN_OPERATOR = new DistinctTypeLessThanOperator();\n\n    private DistinctTypeLessThanOperator()\n    {\n        super(LESS_THAN,\n                ImmutableList.of(withVariadicBound(\"T\", DISTINCT_TYPE)),\n                ImmutableList.of(),\n                parseTypeSignature(BOOLEAN),\n                ImmutableList.of(parseTypeSignature(\"T\"), parseTypeSignature(\"T\")));\n    }\n\n    @Override\n    public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager)\n    {\n        DistinctType type = (DistinctType) boundVariables.getTypeVariable(\"T\");\n        // We assume that a distinct type is orderable iff its parent is orderable.\n        // So we only check orderability of the common supertype when comparing.\n        if (!type.isOrderable()) {\n            throw new PrestoException(INVALID_ARGUMENTS, format(\"Type %s does not allow ordering\", type.getDisplayName()));\n        }\n        Type baseType = type.getBaseType();\n        FunctionHandle functionHandle = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(baseType, baseType));\n\n        return new BuiltInScalarFunctionImplementation(\n                false,\n                ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)),\n                functionAndTypeManager.getJavaScalarFunctionImplementation(functionHandle).getMethodHandle(),\n                Optional.empty());\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":72,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/distinct/DistinctTypeLessThanOperator.java#L42-L72","documentation":"The less-than operator for DISTINCT types requires the distinct type to be orderable. During specialize(), Presto verifies isOrderable() on the bound DistinctType because the operator is implemented by resolving a LESS_THAN operator on the type's base type; if the base type has no ordering, resolution is impossible and INVALID_ARGUMENTS is thrown. A distinct type is assumed orderable iff its parent (base) type is orderable.","triggerScenarios":"Calling the less_than operator with a DISTINCT type argument whose base type is not orderable; the check fails in specialize() when bound type variable 'T' has isOrderable() == false.","commonSituations":"Comparing distinct-typed columns with < in WHERE clauses, JOIN conditions, or ORDER BY where the distinct type was declared over a non-orderable base type.","solutions":["Verify the distinct type's base type is orderable before using < comparisons","Use equality comparison instead of ordering for non-orderable types","Cast operands to an orderable type and compare those","Recreate the distinct type over an orderable base type"],"exampleFix":"// before\nSELECT * FROM t WHERE a < b; -- a,b are distinct type over non-orderable base\n// after\nSELECT * FROM t WHERE a = b; -- equality only, or cast to an orderable type","handlingStrategy":"validation","validationCode":"if (!distinctType.isOrderable()) { throw new IllegalArgumentException(\"Type \" + distinctType.getDisplayName() + \" does not allow ordering; use equality instead\"); }","typeGuard":"if (type instanceof DistinctType && ((DistinctType) type).isOrderable()) { /* safe to use < operator */ }","tryCatchPattern":"try { return functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(baseType, baseType)); } catch (PrestoException e) { if (INVALID_ARGUMENTS.toErrorCode().equals(e.getErrorCode())) { /* rewrite to equality or cast */ } throw e; }","preventionTips":["Check isOrderable() before generating < comparisons against distinct types","Only declare distinct types over orderable base types","Use equality predicates when the base type lacks ordering","Cover distinct-type comparisons in unit tests"],"tags":["presto","sql","distinct-type","ordering","invalid-arguments"],"backgroundTag":"type-not-orderable","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"}