apache/seatunnel · error · SeaTunnelException

Failed to querySQLResult

Error message

Failed to querySQLResult

What it means

SapHanaCatalog.tableExists() wraps any SQLException thrown while running the table-existence probe query into a SeaTunnelException with the message 'Failed to querySQLResult'. This means the JDBC metadata lookup itself failed (connection problem, bad credentials, malformed URL, or SQL error), rather than the table simply not existing. The DatabaseNotExistException path is caught separately and safely returns false, so this exception indicates a genuine query failure.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/saphana/SapHanaCatalog.java:202

                                this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
                                String.format(
                                        getListViewSql(tablePath.getDatabaseName())
                                                + " AND VIEW_NAME = '%s'",
                                        tablePath.getTableName()))
                        || querySQLResultExists(
                                this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
                                String.format(
                                        getListSynonymSql(tablePath.getDatabaseName())
                                                + " AND SYNONYM_NAME = '%s'",
                                        tablePath.getSchemaAndTableName()));
            }
            return querySQLResultExists(
                    this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
                    getTableWithConditionSql(tablePath));
        } catch (DatabaseNotExistException e) {
            return false;
        } catch (SQLException e) {
            throw new SeaTunnelException("Failed to querySQLResult", e);
        }
    }

    public CatalogTable getTable(TablePath tablePath)
            throws CatalogException, TableNotExistException {
        if (!tableExists(tablePath)) {
            throw new TableNotExistException(catalogName, tablePath);
        }
        String dbUrl;
        if (StringUtils.isNotBlank(tablePath.getDatabaseName())) {
            dbUrl = getUrlFromDatabaseName(tablePath.getDatabaseName());
        } else {
            dbUrl = getUrlFromDatabaseName(defaultDatabase);
        }
        Connection conn = getConnection(dbUrl);
        TablePath originalTablePath = tablePath;
        if (listSynonym(tablePath.getDatabaseName()).contains(tablePath.getTableName())) {
            String sql =

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check the wrapped SQLException cause for the root reason (connect timeout, auth failure, SQL syntax).
  2. Verify the JDBC URL and databaseName resolve correctly (getUrlFromDatabaseName) and the HANA instance is reachable on the SQL port.
  3. Test connectivity with a plain JDBC client (e.g. DBeaver or a small Java snippet) using the same URL/credentials.
  4. Escape or sanitize schema/table names in the TablePath so the generated condition SQL is valid.

Example fix

// before
try {
    exists = catalog.tableExists(TablePath.of(db, "my$table"));
} catch (SeaTunnelException e) { /* opaque */ }
// after
TablePath tp = TablePath.of("MYDB", "MY_TABLE"); // sanitized, uppercase HANA identifiers
if (!catalog.databaseExists(tp.getDatabaseName())) {
    throw new IllegalArgumentException("database not reachable: " + tp.getDatabaseName());
}
boolean exists = catalog.tableExists(tp);
Defensive patterns

Strategy: try-catch

Validate before calling

// java
if (!catalog.databaseExists(tablePath.getDatabaseName())) {
    throw new IllegalArgumentException("database unreachable/missing: " + tablePath.getDatabaseName());
}

Try / catch

// java
try {
    boolean exists = catalog.tableExists(tablePath);
} catch (SeaTunnelException e) {
    Throwable root = e.getCause(); // SQLException with real reason
    LOG.error("HANA tableExists probe failed", root);
    throw new RuntimeException("metadata probe failed: " + root.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling SapHanaCatalog.tableExists (directly or indirectly via getTable) when the JDBC connection to SAP HANA drops mid-query, credentials are invalid, the database name does not map to a valid HANA URL, or the generated getTableWithConditionSql SQL is rejected by the server (e.g. special characters in schema/table names breaking the condition SQL).

Common situations: Network/firewall issues between SeaTunnel and the HANA instance; wrong username/password in catalog config; using a databaseName that is not a valid HANA tenant database; table/schema identifiers containing quotes that break the hand-built SQL string.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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