prestodb/presto · error · SQLException
Error fetching results
Error message
Error fetching results
What it means
ResultSet.next() advances the row cursor by pulling the next row from the query results stream. Any RuntimeException raised while fetching (transport failure, protocol error, server-side failure surfacing through the client) is wrapped into a SQLException with message "Error fetching results" and the original cause attached — unless the cause is already a SQLException, which is rethrown as-is. It means results could not be retrieved from the Presto coordinator, not that the result set was exhausted.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:157
@Override
public boolean next()
throws SQLException
{
checkOpen();
try {
if (!results.hasNext()) {
row.set(null);
return false;
}
row.set(results.next());
return true;
}
catch (RuntimeException e) {
if (e.getCause() instanceof SQLException) {
throw (SQLException) e.getCause();
}
throw new SQLException("Error fetching results", e);
}
}
@Override
public void close()
throws SQLException
{
closed.set(true);
client.close();
}
@Override
public boolean wasNull()
throws SQLException
{
return wasNull.get();
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Inspect the cause chain (getCause()) for the real transport or server error and address it
- Retry the whole query (re-execute the statement) with a fresh ResultSet; result sets are not resumable
- Reduce result size (LIMIT, pagination, or server paging) to shorten streaming time
- Check coordinator health/load-balancer idle timeouts and increase them if large gaps between pages occur
Example fix
// before
while (rs.next()) { ... } // whole loop dies on one transient failure
// after
try {
while (rs.next()) { ... }
}
catch (SQLException e) {
e.getCause().printStackTrace();
rs = stmt.executeQuery(sql); // re-run the query and start over
} Defensive patterns
Strategy: retry
Try / catch
boolean done = false;
for (int attempt = 0; attempt < 3 && !done; attempt++) {
try (ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) { /* consume rows */ }
done = true;
}
catch (SQLException e) {
if (e.getMessage().equals("Error fetching results") && attempt < 2) continue; // re-run whole query
throw e;
}
} Prevention
- Consume result sets promptly; idle gaps between next() calls can hit idle timeouts
- Keep results small with LIMIT/pagination instead of streaming huge result sets
- Always log the full cause chain — the wrapped cause names the real transport/server failure
- Monitor coordinator health and load-balancer/proxy idle timeouts
When it happens
Trigger: Calling next() when the underlying HTTP connection to the coordinator drops mid-stream, the server returns a query error/failure while streaming pages, or the results client throws an unchecked exception (e.g. deserialization failure of a results page).
Common situations: Long-running queries whose pages take longer than coordinator limits; coordinator restarts or load balancer idle timeouts during result streaming; network partitions; query killed server-side mid-iteration while the client loops over rows.
Related errors
- Error fetching version from server
- Result set type must be TYPE_FORWARD_ONLY
- Result set concurrency must be CONCUR_READ_ONLY
- Invalid date from server:
- Expected column to be a timestamp type but is
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/b0769fcafac8b517.
Report an issue: GitHub.