apache/seatunnel · error · SQLException

No result returned after running query [${rowCountQuery}]

Error message

No result returned after running query [${rowCountQuery}]

What it means

Db2Utils.queryApproximateRowCnt runs a SYSCAT.TABLES row-count query for a table and maps the single-row result. If the ResultSet has no row (the table row is absent from SYSCAT.TABLES), it throws this SQLException. This indicates the catalog lookup returned nothing for the requested schema/table.

Source

Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-db2/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/db2/utils/Db2Utils.java:94

                    }
                    return SourceRecordUtils.rowToArray(rs, 2);
                });
    }

    public static long queryApproximateRowCnt(JdbcConnection jdbc, TableId tableId)
            throws SQLException {
        // SYSCAT.TABLES.CARD is the optimizer's cardinality estimate. It avoids COUNT(*) during
        // split planning and falls back to 0 when RUNSTATS has not populated the estimate yet.
        final String rowCountQuery =
                String.format(
                        "SELECT COALESCE(MAX(CARD), 0) FROM SYSCAT.TABLES "
                                + "WHERE TABSCHEMA = '%s' AND TABNAME = '%s'",
                        tableId.schema(), tableId.table());
        return jdbc.queryAndMap(
                rowCountQuery,
                rs -> {
                    if (!rs.next()) {
                        throw new SQLException(
                                String.format(
                                        "No result returned after running query [%s]",
                                        rowCountQuery));
                    }
                    return rs.getLong(1);
                });
    }

    public static Object queryMin(
            JdbcConnection jdbc, TableId tableId, String columnName, Object excludedLowerBound)
            throws SQLException {
        final String minQuery =
                String.format(
                        "SELECT MIN(%s) FROM %s WHERE %s > ?",
                        quote(columnName), quote(tableId), quote(columnName));
        return jdbc.prepareQueryAndMap(
                minQuery,
                ps -> ps.setObject(1, excludedLowerBound),

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Verify the table exists: SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE TABSCHEMA='<schema>' AND TABNAME='<table>'
  2. Check table-name case in the connector config — DB2 identifiers are usually uppercase
  3. Confirm the connection points to the database that actually contains the table
  4. Re-run the job if the table was dropped/recreated concurrently

Example fix

// before: tableId built from lowercase config
TableId.of("MYDB", "myschema", "mytable");
// after: normalize to DB2 upper-case identifiers
TableId.of("MYDB", "MYSCHEMA", "MYTABLE");
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check the table exists in DB2 catalog
SELECT COUNT(*) FROM SYSCAT.TABLES WHERE TABSCHEMA = 'MYSCHEMA' AND TABNAME = 'MYTABLE';

Try / catch

try { long cnt = Db2Utils.queryApproximateRowCnt(jdbc, tableId); } catch (SQLException e) { if (e.getMessage().contains("No result returned")) { /* fallback: table missing — check name case/schema */ } throw e; }

Prevention

When it happens

Trigger: Calling queryApproximateRowCnt(jdbc, tableId) for a tableId whose TABSCHEMA/TABNAME row does not exist in SYSCAT.TABLES (typo in table name, wrong case, or table dropped between split enumeration and count).

Common situations: Table name casing mismatch (DB2 stores uppercase by default); table dropped concurrently; connector configured for a table not present in the current database.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/e17bc7e98aff7a5a. Report an issue: GitHub.