apache/shardingsphere · error · UnsupportedOperationException
Unsupported Returning Expression
Error message
Unsupported Returning Expression
What it means
Thrown by OracleDMLStatementVisitor when a RETURNING clause projection cannot be mapped: createProjection handles ProjectionSegment, ComplexExpressionSegment, SimpleExpressionSegment, and generic ExpressionSegment, and throws UnsupportedOperationException('Unsupported Returning Expression') for anything else. It is a visitor coverage gap — the parsed AST node type has no projection mapping rule, not a user syntax error.
Source
Thrown at parser/sql/engine/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/engine/oracle/visitor/statement/type/OracleDMLStatementVisitor.java:1055
}
return new ReturningSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), projections);
}
private ProjectionSegment createReturningProjection(final ExprContext ctx) {
ASTNode projection = visit(ctx);
if (projection instanceof ProjectionSegment) {
return (ProjectionSegment) projection;
}
if (projection instanceof ComplexExpressionSegment) {
return (ProjectionSegment) createProjectionForComplexExpressionSegment(projection, null);
}
if (projection instanceof SimpleExpressionSegment) {
return createExpressionProjectionSegment((ExpressionSegment) projection, null);
}
if (projection instanceof ExpressionSegment) {
return (ProjectionSegment) createProjectionForExpressionSegment(projection, null);
}
throw new UnsupportedOperationException("Unsupported Returning Expression");
}
@Override
public ASTNode visitSelectList(final SelectListContext ctx) {
ProjectionsSegment result = new ProjectionsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
Collection<ProjectionSegment> projections = new LinkedList<>();
if (null != ctx.unqualifiedShorthand()) {
projections.add(new ShorthandProjectionSegment(ctx.unqualifiedShorthand().getStart().getStartIndex(), ctx.unqualifiedShorthand().getStop().getStopIndex()));
result.getProjections().addAll(projections);
return result;
}
for (SelectProjectionContext each : ctx.selectProjection()) {
projections.add((ProjectionSegment) visit(each));
}
result.getProjections().addAll(projections);
return result;
}
View on GitHub (pinned to e952770a21)
Solutions
- Simplify the RETURNING list to plain columns or simple expressions
- Move the complex computation out of RETURNING (e.g. return the column, compute in the app)
- Upgrade ShardingSphere — visitor coverage for RETURNING expressions improves across releases
- If extending the project, add a branch mapping the missing segment type in createProjection
Example fix
// before INSERT INTO t (id) VALUES (seq.NEXTVAL) RETURNING id*2+1 INTO x // after INSERT INTO t (id) VALUES (seq.NEXTVAL) RETURNING id INTO x
Defensive patterns
Strategy: try-catch
Try / catch
try { parserEngine.parse(sql); }
catch (UnsupportedOperationException e) {
// coverage gap, not bad syntax: simplify the RETURNING list and retry once with plain columns
log.warn("Unsupported RETURNING expression, falling back to column-only RETURNING", e);
} Prevention
- Keep RETURNING lists to plain columns
- Test every RETURNING shape you use against the exact ShardingSphere version in CI
When it happens
Trigger: Oracle INSERT/UPDATE/DELETE ... RETURNING with an exotic expression whose visited AST node implements none of the four recognized segment interfaces: e.g. special PL/SQL-ish expressions, newly added segment types from newer grammars, or dialect-specific function segments.
Common situations: Using RETURNING with unusual expressions in Oracle-sharded tables; ShardingSphere version where the Oracle RETURNING grammar accepts an expression the visitor cannot classify; upgrading adds new segment types not yet wired into this chain.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/e01cfbdcd2bf002b.
Report an issue: GitHub.