prestodb/presto · error · IllegalArgumentException

Unsupported flip non-comparison operator:

Error message

Unsupported flip non-comparison operator: 

What it means

OperatorType.flip() only maps comparison operators (equality, ordering, IS_DISTINCT_FROM) to their flipped counterparts. Passing any non-comparison operator (arithmetic, logical, etc.) hits the default branch and throws IllegalArgumentException.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/function/OperatorType.java:117

    public static OperatorType flip(OperatorType operator)
    {
        switch (operator) {
            case EQUAL:
                return EQUAL;
            case NOT_EQUAL:
                return NOT_EQUAL;
            case LESS_THAN:
                return GREATER_THAN;
            case LESS_THAN_OR_EQUAL:
                return GREATER_THAN_OR_EQUAL;
            case GREATER_THAN:
                return LESS_THAN;
            case GREATER_THAN_OR_EQUAL:
                return LESS_THAN_OR_EQUAL;
            case IS_DISTINCT_FROM:
                return IS_DISTINCT_FROM;
            default:
                throw new IllegalArgumentException("Unsupported flip non-comparison operator: " + operator);
        }
    }

    public static OperatorType negate(OperatorType operator)
    {
        switch (operator) {
            case EQUAL:
                return NOT_EQUAL;
            case NOT_EQUAL:
                return EQUAL;
            case LESS_THAN:
                return GREATER_THAN_OR_EQUAL;
            case LESS_THAN_OR_EQUAL:
                return GREATER_THAN;
            case GREATER_THAN:
                return LESS_THAN_OR_EQUAL;
            case GREATER_THAN_OR_EQUAL:
                return LESS_THAN;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Only call flip() on comparison-family operators; guard with an EnumSet of comparable operators first
  2. Add a case for any newly added operator to flip()'s switch
  3. Use negate() or explicit mapping for non-comparison operators as appropriate
  4. Check the operator kind (e.g. isComparisonOperator) before flipping

Example fix

// before
OperatorType flipped = OperatorType.flip(operator); // operator may be ADD
// after
if (COMPARISON_OPERATORS.contains(operator)) {
    OperatorType flipped = OperatorType.flip(operator);
}
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<OperatorType> COMPARISONS = EnumSet.of(
    OperatorType.EQUAL, OperatorType.NOT_EQUAL, OperatorType.LESS_THAN,
    OperatorType.LESS_THAN_OR_EQUAL, OperatorType.GREATER_THAN,
    OperatorType.GREATER_THAN_OR_EQUAL, OperatorType.IS_DISTINCT_FROM);
if (!COMPARISONS.contains(op)) throw new IllegalArgumentException("not flippable: " + op);

Type guard

boolean isComparison(OperatorType op) { return COMPARISONS.contains(op); }

Try / catch

try { flipped = OperatorType.flip(op); } catch (IllegalArgumentException e) { /* fall back: keep original operator or handle non-comparison case */ }

Prevention

When it happens

Trigger: Calling OperatorType.flip(operator) with a non-comparison OperatorType such as ADD, SUBTRACT, AND, OR, HASH_CODE, etc.

Common situations: Rewriting commuted predicates in optimizer rules where the operator came from arbitrary function resolution; version drift where a new OperatorType enum constant was added but flip() was not updated; applying flip to an operator obtained from a generic expression tree.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/785db6e93d478c97. Report an issue: GitHub.