apache/shardingsphere · error · UnsupportedOperationException

Unsupported operator: %s in page expression

Error message

Unsupported operator: %s in page expression

What it means

Thrown by ExpressionRowNumberValueSegment.getValueFromBinaryOperationExpression when a pagination expression is a binary operation whose operator is not +, -, *, or /. The evaluator recursively resolves left/right values and switches on the operator string; division, multiplication, addition, subtraction are supported, anything else (%, concatenation, comparisons) throws UnsupportedOperationException naming the operator.

Source

Thrown at parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/dml/pagination/rownum/ExpressionRowNumberValueSegment.java:75

        }
        throw new UnsupportedOperationException(String.format("Unsupported expression: %s in page expression", expressionSegment.getClass().getName()));
    }
    
    private Long getValueFromBinaryOperationExpression(final BinaryOperationExpression binaryOperationExpression, final List<Object> params) {
        String operator = binaryOperationExpression.getOperator();
        Long leftValue = getValueFromExpression(binaryOperationExpression.getLeft(), params);
        Long rightValue = getValueFromExpression(binaryOperationExpression.getRight(), params);
        switch (operator) {
            case "+":
                return leftValue + rightValue;
            case "-":
                return leftValue - rightValue;
            case "*":
                return leftValue * rightValue;
            case "/":
                return leftValue / rightValue;
            default:
                throw new UnsupportedOperationException(String.format("Unsupported operator: %s in page expression", operator));
        }
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Express the pagination bound with only +, -, *, / arithmetic
  2. Precompute values like modulo results in the application and bind them as parameter markers or literals
  3. Remove comparison/logical operators from the value expression (they belong outside the row-number bound)

Example fix

// before
WHERE ROWNUM <= 10 % 3

// after
WHERE ROWNUM <= 1
Defensive patterns

Strategy: validation

Validate before calling

Set<String> ARITH = Set.of("+", "-", "*", "/");
if (!ARITH.contains(op)) throw new IllegalArgumentException("Pagination bound supports only + - * /");

Try / catch

try { rewriteEngine.rewrite(query); } catch (UnsupportedOperationException e) { /* precompute the value and re-bind */ }

Prevention

When it happens

Trigger: ROWNUM-style pagination using modulo ('ROWNUM % 10'), bitwise operators, or any non-arithmetic operator inside the value expression; also triggered if a grammar change produces an operator token string not in the four supported cases.

Common situations: Ported pagination idioms from other languages/databases (% for cycling); generated SQL using modulo arithmetic for paging; edge operator tokens after upgrades.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/d1c21532ff201d29. Report an issue: GitHub.