{"record":{"id":"fe2f09dc79ef47af","repo":"prestodb/presto","slug":"invalid-arguments-fe2f09","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/DistinctTypeGreaterThanOperator.java","lineNumber":58,"sourceCode":"        extends SqlOperator\n{\n    public static final DistinctTypeGreaterThanOperator DISTINCT_TYPE_GREATER_THAN_OPERATOR = new DistinctTypeGreaterThanOperator();\n\n    private DistinctTypeGreaterThanOperator()\n    {\n        super(GREATER_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        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, 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/DistinctTypeGreaterThanOperator.java#L40-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT * FROM t WHERE d_col > d_threshold; -- non-orderable distinct type\n// after\nSELECT * FROM t WHERE CAST(d_col AS bigint) > CAST(d_threshold AS bigint);","handlingStrategy":"type-guard","validationCode":"-- guard > usage: only apply when the type supports ordering\n-- if (!distinctType.isOrderable()) rewrite comparison on base type","typeGuard":"boolean canOrder(DistinctType t) {\n    return t != null && t.isOrderable();\n}","tryCatchPattern":"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; } }","preventionTips":["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."],"tags":["presto","sql","distinct-type","ordering","comparison"],"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"}