{"record":{"id":"680358e6ee9b9b6c","repo":"prestodb/presto","slug":"invalid-arguments-680358","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/DistinctTypeGreaterThanOrEqualOperator.java","lineNumber":58,"sourceCode":"        extends SqlOperator\n{\n    public static final DistinctTypeGreaterThanOrEqualOperator DISTINCT_TYPE_GREATER_THAN_OR_EQUAL_OPERATOR = new DistinctTypeGreaterThanOrEqualOperator();\n\n    private DistinctTypeGreaterThanOrEqualOperator()\n    {\n        super(GREATER_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(GREATER_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/DistinctTypeGreaterThanOrEqualOperator.java#L40-L70","documentation":"The greater-than-or-equal operator for DISTINCT types requires the distinct type's underlying base type to support ordering. During specialization, Presto checks whether the bound type variable T is orderable; if not, it cannot resolve a >= operator on the base type, so it throws INVALID_ARGUMENTS. This guards against comparing values of a type that defines no ordering semantics.","triggerScenarios":"Invoking the greater_than_or_equal operator on a DISTINCT type whose base type is not orderable (e.g. a distinct type over a non-orderable type such as a map or complex type). The exception is raised in specialize() when boundVariables type variable 'T' resolves to a DistinctType whose isOrderable() returns false.","commonSituations":"Users define a distinct type over a non-orderable base type and then attempt to use >= comparisons or ORDER BY/GROUP BY/min-max operations that desugar to the ordering operator; schema evolution or version changes where a base type lost orderability.","solutions":["Check type.isOrderable() for the distinct type before using ordering operators like >=, <, <=, >","Use only equality-based comparisons (equals operator) for non-orderable distinct types","Cast the values to an orderable type or compare the underlying base-type values instead","Redefine the distinct type over an orderable base type"],"exampleFix":"// before\nSELECT * FROM t WHERE my_distinct_col >= my_distinct_value; -- base type not orderable\n// after\nSELECT * FROM t WHERE CAST(my_distinct_col AS base_type) >= CAST(my_distinct_value AS base_type); -- or use equality","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 ordering operators */ }","tryCatchPattern":"try { return functionAndTypeManager.resolveOperator(GREATER_THAN_OR_EQUAL, fromTypes(baseType, baseType)); } catch (PrestoException e) { if (e.getErrorCode().getCode() == INVALID_ARGUMENTS.toErrorCode().getCode()) { /* fall back to equality semantics */ } throw e; }","preventionTips":["Call isOrderable() on the type before emitting ordering operators in generated SQL","Restrict distinct types in your schema to orderable base types","Prefer equality for non-orderable types in query builders","Add tests covering every distinct type used in ORDER BY/comparison paths"],"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"}