apache/seatunnel · error · RuntimeException

Failed to build the split data read statement.

Error message

Failed to build the split data read statement.

What it means

A generic RuntimeException wrapping any failure while building the PreparedStatement that reads rows for a snapshot split (primary-key range query). Any SQL construction, parameter binding, or driver error during statement creation is reported with this message.

Source

Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java:364

            if (isFirstSplit) {
                for (int i = 0; i < primaryKeyNum; i++) {
                    statement.setObject(i + 1, splitEnd[i]);
                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);
                }
            } else if (isLastSplit) {
                for (int i = 0; i < primaryKeyNum; i++) {
                    statement.setObject(i + 1, splitStart[i]);
                }
            } else {
                for (int i = 0; i < primaryKeyNum; i++) {
                    statement.setObject(i + 1, splitStart[i]);
                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);
                    statement.setObject(i + 1 + 2 * primaryKeyNum, splitEnd[i]);
                }
            }
            return statement;
        } catch (Exception e) {
            throw new RuntimeException("Failed to build the split data read statement.", e);
        }
    }

    private static String getPrimaryKeyColumnsProjection(SeaTunnelRowType rowType) {
        StringBuilder sql = new StringBuilder();
        for (Iterator<String> fieldNamesIt = Arrays.stream(rowType.getFieldNames()).iterator();
                fieldNamesIt.hasNext(); ) {
            sql.append(fieldNamesIt.next());
            if (fieldNamesIt.hasNext()) {
                sql.append(" , ");
            }
        }
        return sql.toString();
    }

    private static String buildSplitQuery(
            Table table,
            SeaTunnelRowType rowType,

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the wrapped cause 'e' in the stack trace — it contains the real driver error
  2. Verify the table has a usable primary key and its columns appear in the configured rowType
  3. Check split boundary values are of types the Postgres JDBC driver can bind
  4. Update the Postgres JDBC driver to the latest version
  5. If a custom type is the cause, exclude that column from the split key or handle it via type mapping

Example fix

// before
statement.setObject(i + 1, splitStart[i]); // fails for UUID/JSONB
// after
Object v = splitStart[i];
if (v instanceof java.util.UUID) {
    statement.setObject(i + 1, v, java.sql.Types.OTHER);
} else {
    statement.setObject(i + 1, v);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: check primary key columns exist and types are bindable
for (String pk : primaryKeyColumns) {
    int idx = rowType.indexOf(pk);
    if (idx < 0) throw new IllegalArgumentException("PK column missing from rowType: " + pk);
}

Try / catch

try {
    stmt = PostgresUtils.readTableSplitDataStatement(jdbc, querySql, splitStart, splitEnd, pkCols);
} catch (RuntimeException e) {
    throw new RuntimeException("split statement build failed: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: PostgresUtils.readTableSplitDataStatement(...) fails when setObject() rejects a split boundary value type, the rowType/primaryKey columns are mismatched, or the generated SQL is invalid (e.g. missing primary key columns, bad quoting).

Common situations: Tables with exotic primary-key column types (JSONB, arrays, UUID) that the JDBC driver cannot bind via setObject; split boundaries computed from incompatible schema snapshots; malformed table identifiers after case-folding.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


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