prestodb/presto · error · SQLFeatureNotSupportedException
afterLast
Error message
afterLast
What it means
PrestoResultSet throws SQLFeatureNotSupportedException("afterLast") because Presto result sets are forward-only; the JDBC driver does not buffer rows, so scrollable navigation methods cannot be implemented. Calling afterLast() always fails unconditionally, regardless of result set state.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:650
@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");
}
@Override
public int getRow()View on GitHub (pinned to 55bb57d202)
Solutions
- Rewrite the query with ORDER BY and iterate forward from the beginning instead of using afterLast()
- Count rows with a separate SELECT COUNT(*) query instead of repositioning to the end
- Materialize rows into a local List/Collection during the forward pass, then index it in memory
- Wrap the statement request only if the driver ever supports scrollable types; currently it does not
Example fix
// before
if (rs.last()) { int count = rs.getRow(); }
// after
int count = 0;
while (rs.next()) { count++; } Defensive patterns
Strategy: try-catch
Validate before calling
DatabaseMetaData md = conn.getMetaData();
if (!md.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) { /* avoid navigation calls */ } Try / catch
try { rs.afterLast(); } catch (SQLFeatureNotSupportedException e) { /* fall back to forward iteration */ } Prevention
- Treat Presto result sets as TYPE_FORWARD_ONLY regardless of requested type
- Count rows with SELECT COUNT(*) instead of navigating to the end
- Buffer rows locally if random access is needed
When it happens
Trigger: Calling ResultSet.afterLast() on a PrestoResultSet obtained from a Presto JDBC Statement, regardless of statement type or fetch configuration.
Common situations: Generic JDBC frameworks (ORMs, reporting tools, Spring JdbcTemplate) that iterate a result set first and then reposition via afterLast() to count rows or access data in reverse.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/f3ce25abb5232776.
Report an issue: GitHub.