apache/shardingsphere · warning · SQLFeatureNotSupportedException
beforeFirst
Error message
beforeFirst
What it means
beforeFirst() on a federation result set throws SQLFeatureNotSupportedException: federation results are forward-only streams over the Calcite execution, and AbstractUnsupportedOperationSQLFederationResultSet explicitly rejects repositioning methods. Calling beforeFirst() to restart iteration is not possible on this result set.
Source
Thrown at kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java:60
@Override
public boolean isAfterLast() throws SQLException {
throw new SQLFeatureNotSupportedException("isAfterLast");
}
@Override
public boolean isFirst() throws SQLException {
throw new SQLFeatureNotSupportedException("isFirst");
}
@Override
public boolean isLast() throws SQLException {
throw new SQLFeatureNotSupportedException("isLast");
}
@Override
public void beforeFirst() throws SQLException {
throw new SQLFeatureNotSupportedException("beforeFirst");
}
@Override
public void afterLast() throws SQLException {
throw new SQLFeatureNotSupportedException("afterLast");
}
@Override
public boolean first() throws SQLException {
throw new SQLFeatureNotSupportedException("first");
}
@Override
public boolean last() throws SQLException {
throw new SQLFeatureNotSupportedException("last");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Buffer the rows once (List) and do multiple passes in memory instead of calling beforeFirst().
- Use a scroll-insensitive result set at the application level by wrapping the fetched data, not the live ResultSet.
- Disable SQL federation for this statement/rule so a driver result set supporting beforeFirst() is returned (subject to driver TYPE settings).
Example fix
// before processMetadata(rs); rs.beforeFirst(); processData(rs); // after List<Row> rows = fetchAll(rs); processMetadata(rows); processData(rows);
Defensive patterns
Strategy: fallback
Validate before calling
if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
rows = fetchAll(rs); // single forward pass; re-iterate the list instead of beforeFirst()
} Try / catch
try {
rs.beforeFirst();
} catch (final SQLFeatureNotSupportedException ex) {
// re-execute the query or use the buffered copy taken during the first pass
} Prevention
- Buffer federated results in a List for multi-pass consumers.
- Avoid beforeFirst()/afterLast()/first() on ShardingSphere result sets.
- Set reporting tools to streaming single-pass mode where possible.
When it happens
Trigger: Application/ORM code calls rs.beforeFirst() to re-iterate a result set returned by a federated query through ShardingSphere (e.g. some report engines call beforeFirst after a metadata pass).
Common situations: Two-pass processing (metadata then data) in reporting tools; ORMs emulating scroll-insensitive result sets; generic JDBC utility code that resets cursors; works fine against plain MySQL driver, fails when federation kicks in.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/6e32225229aaab9d.
Report an issue: GitHub.