apache/shardingsphere · error · UnsupportedOperationException
Unsupported expression: %s in page expression
Error message
Unsupported expression: %s in page expression
What it means
Thrown by ExpressionRowNumberValueSegment.getValueFromExpression when evaluating a row-number pagination expression at rewrite time: only ParameterMarkerExpressionSegment, BinaryOperationExpression, and LiteralExpressionSegment are evaluatable. Any other ExpressionSegment subclass triggers UnsupportedOperationException naming the segment class. This is runtime pagination-math evaluation (Oracle/rownum-style LIMIT/OFFSET folding), not initial parsing.
Source
Thrown at parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/dml/pagination/rownum/ExpressionRowNumberValueSegment.java:58
*
* @param params parameters
* @return value
*/
public Long getValue(final List<Object> params) {
return getValueFromExpression(expressionSegment, params);
}
private Long getValueFromExpression(final ExpressionSegment expressionSegment, final List<Object> params) {
if (expressionSegment instanceof ParameterMarkerExpressionSegment) {
return null == params || params.isEmpty() ? 0L : Long.parseLong(params.get(((ParameterMarkerExpressionSegment) expressionSegment).getParameterMarkerIndex()).toString());
}
if (expressionSegment instanceof BinaryOperationExpression) {
return getValueFromBinaryOperationExpression((BinaryOperationExpression) expressionSegment, params);
}
if (expressionSegment instanceof LiteralExpressionSegment) {
return Long.parseLong(expressionSegment.getText());
}
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
- Rewrite the pagination expression using literals, parameter markers, or +/-/*// over them
- Compute the bound in application code and pass it as a single parameter marker
- Avoid functions or exotic expressions inside ROWNUM/row-number pagination predicates
- If the segment type is genuinely evaluatable, extend getValueFromExpression in a fork/PR
Example fix
// before SELECT * FROM t WHERE ROWNUM <= CEIL(10/2) // after SELECT * FROM t WHERE ROWNUM <= 5
Defensive patterns
Strategy: validation
Validate before calling
// Fold pagination bounds in app code; only literals/markers/+,-,*,/ survive rewrite long bound = pageSize + offset; String sql = "SELECT * FROM (SELECT t.*, ROWNUM rn FROM t) WHERE rn <= " + bound;
Try / catch
try { rewriteEngine.rewrite(query); } catch (UnsupportedOperationException e) { /* reissue with folded literal bound */ } Prevention
- Compute pagination values app-side and bind them as parameters or literals
- Never put functions or exotic expressions inside ROWNUM bounds
When it happens
Trigger: A rownum-based pagination predicate whose value expression is, e.g., a function call (LEVEL, sequence, SYSDATE), a case expression, or any segment type beyond the three handled — getValueFromExpression is called during SQL rewrite to fold the numeric value and cannot resolve it.
Common situations: ROWNUM <= ? + 10 works (binary op), but ROWNUM <= some_func(1) or nested function expressions fail; upgrades that change how an expression is visited (reclassified segments); dialect migrations bringing non-numeric-friendly pagination expressions.
Related errors
- Unsupported operator: %s in page expression
- Unsupported type: %s
- absolute
- unsupported CommonExpressionSegment
- unsupported TableSegment type: %s
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/9b3cbe4b0bdacdea.
Report an issue: GitHub.