prestodb/presto · error · SQLException

Rows is negative

Error message

Rows is negative

What it means

PrestoResultSet.setFetchSize rejects negative values with SQLException("Rows is negative") after checking the result set is open. Non-negative fetch sizes are accepted but otherwise ignored, since Presto streams results in its own pages.

Source

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

            throw new SQLException("Fetch direction must be FETCH_FORWARD");
        }
    }

    @Override
    public int getFetchDirection()
            throws SQLException
    {
        checkOpen();
        return FETCH_FORWARD;
    }

    @Override
    public void setFetchSize(int rows)
            throws SQLException
    {
        checkOpen();
        if (rows < 0) {
            throw new SQLException("Rows is negative");
        }
        // fetch size is ignored
    }

    @Override
    public int getFetchSize()
            throws SQLException
    {
        checkOpen();
        // fetch size is ignored
        return 0;
    }

    @Override
    public int getType()
            throws SQLException
    {
        checkOpen();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Clamp or validate the fetch size to >= 0 before calling setFetchSize
  2. Treat framework sentinel values like -1 as 'do not call setFetchSize'
  3. Note the value is ignored anyway; simply omit the call when tuning Presto fetch behavior

Example fix

// before
rs.setFetchSize(config.getFetchSize()); // may be -1
// after
int size = config.getFetchSize();
if (size >= 0) { rs.setFetchSize(size); }
Defensive patterns

Strategy: validation

Validate before calling

if (rows < 0) {
    throw new IllegalArgumentException("fetchSize must be >= 0");
}
rs.setFetchSize(rows);

Try / catch

try { rs.setFetchSize(cfg); } catch (SQLException e) { if (e.getMessage().contains("Rows is negative")) { /* fix config value */ } }

Prevention

When it happens

Trigger: Calling setFetchSize(rows) with rows < 0 on an open PrestoResultSet.

Common situations: Config-driven fetch sizes where a negative placeholder value (-1 meaning 'unlimited' in some frameworks) leaks into the JDBC call.

Related errors


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