prestodb/presto · error · IllegalArgumentException

Unsupported negate non-comparison operator:

Error message

Unsupported negate non-comparison operator: 

What it means

Sentinel in the operator negation switch: negate() only maps comparison operators (EQUAL, LESS_THAN, etc.); any other OperatorType reaches the default branch and is rejected because negation is undefined for it.

Source

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

    }

    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;
            default:
                throw new IllegalArgumentException("Unsupported negate non-comparison operator: " + operator);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Only call negate on comparison operators
  2. Add an explicit case if a new comparison operator is introduced

Example fix

// before
OperatorType negated = OperatorType.negate(operator); // throws for ADD
// after
if (COMPARISON_OPERATORS.contains(operator)) {
    OperatorType negated = OperatorType.negate(operator);
} else {
    expression = not(expression); // logical negation
}
Defensive patterns

Strategy: type-guard

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);
if (!COMPARISONS.contains(op)) throw new IllegalArgumentException("not negatable: " + op);

Type guard

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

Try / catch

try { negated = OperatorType.negate(op); } catch (IllegalArgumentException e) { expression = NotExpression of original; }

Prevention

When it happens

Trigger: Calling OperatorType.negate(operator) with a non-comparison operator such as ADD, MULTIPLY, IS_NULL, LIKE, etc.

Common situations: NOT-elimination or predicate pushdown rules negating operators sourced from generic expressions; a newly added OperatorType constant missing from the negate switch; misusing negate where flip or logical NOT was intended.

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/2e52c08100aaec9d. Report an issue: GitHub.