{"record":{"id":"301858260eb2fdad","repo":"prestodb/presto","slug":"invalid-arguments-301858","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/DistinctTypeLessThanOrEqualOperator.java","lineNumber":58,"sourceCode":"        extends SqlOperator\n{\n    public static final DistinctTypeLessThanOrEqualOperator DISTINCT_TYPE_LESS_THAN_OR_EQUAL_OPERATOR = new DistinctTypeLessThanOrEqualOperator();\n\n    private DistinctTypeLessThanOrEqualOperator()\n    {\n        super(LESS_THAN_OR_EQUAL,\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        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_OR_EQUAL, 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":40,"sourceCodeEnd":70,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/distinct/DistinctTypeLessThanOrEqualOperator.java#L40-L70","documentation":"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 <=.","triggerScenarios":"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.","commonSituations":"Using <= in range filters, BETWEEN-style predicates, or window functions on columns of a distinct type declared over a non-orderable base type.","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"],"exampleFix":"// before\nSELECT * FROM t WHERE x <= y; -- x,y distinct type, base not orderable\n// after\nSELECT * FROM t WHERE x = y; -- or compare casts of 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_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; }","preventionTips":["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"],"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"}