prestodb/presto · error · SQLFeatureNotSupportedException

isLast

Error message

isLast

What it means

isLast is unsupported for the same reason as the other position probes: Presto result sets are forward-only and cannot look ahead to detect the final row; PrestoResultSet throws SQLFeatureNotSupportedException unconditionally. Look-ahead semantics are incompatible with the streaming model.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:636

    @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()

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Track iteration manually: keep the previous row and emit it only when rs.next() returns true again (or use a 'hasNext' style two-variable loop)
  2. Buffer rows into a collection and iterate by index
  3. Remove separator logic dependence on cursor position

Example fix

// before
while (rs.next()) { emit(rs); if (!rs.isLast()) emitSeparator(); }
// after
boolean first = true;
while (rs.next()) { if (!first) emitSeparator(); emit(rs); first = false; }
Defensive patterns

Strategy: try-catch

Validate before calling

if (rs instanceof com.facebook.presto.jdbc.PrestoResultSet) {
    // emit separators based on your own iteration state, not isLast()
}

Type guard

boolean isPrestoResultSet(ResultSet rs) { return rs instanceof com.facebook.presto.jdbc.PrestoResultSet; }

Try / catch

try {
    boolean last = rs.isLast();
} catch (SQLFeatureNotSupportedException e) {
    // buffer rows or use a two-variable look-back loop
}

Prevention

When it happens

Trigger: Calling rs.isLast() on a PrestoResultSet, commonly to avoid a trailing separator in generated output.

Common situations: CSV/JSON writers that need to know the last row; migration of scrollable-result-set logic to Presto.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/eaff351cc8ef9141. Report an issue: GitHub.