{"record":{"id":"6e32225229aaab9d","repo":"apache/shardingsphere","slug":"beforefirst-6e3222","errorCode":null,"errorMessage":"beforeFirst","messagePattern":"beforeFirst","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"warning","filePath":"kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java","lineNumber":60,"sourceCode":"    \n    @Override\n    public boolean isAfterLast() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"isAfterLast\");\n    }\n    \n    @Override\n    public boolean isFirst() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"isFirst\");\n    }\n    \n    @Override\n    public boolean isLast() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"isLast\");\n    }\n    \n    @Override\n    public void beforeFirst() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"beforeFirst\");\n    }\n    \n    @Override\n    public void afterLast() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"afterLast\");\n    }\n    \n    @Override\n    public boolean first() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"first\");\n    }\n    \n    @Override\n    public boolean last() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"last\");\n    }\n    \n    @Override","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java#L42-L78","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"// before\nprocessMetadata(rs);\nrs.beforeFirst();\nprocessData(rs);\n// after\nList<Row> rows = fetchAll(rs);\nprocessMetadata(rows);\nprocessData(rows);","handlingStrategy":"fallback","validationCode":"if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {\n    rows = fetchAll(rs); // single forward pass; re-iterate the list instead of beforeFirst()\n}","typeGuard":null,"tryCatchPattern":"try {\n    rs.beforeFirst();\n} catch (final SQLFeatureNotSupportedException ex) {\n    // re-execute the query or use the buffered copy taken during the first pass\n}","preventionTips":["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."],"tags":["sql-federation","jdbc","resultset","cursor"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}