apache/seatunnel · warning
Failed to get primary key for table {}.{}, will create table
Error message
Failed to get primary key for table {}.{}, will create table without primary key What it means
While building the ClickHouse source catalog in createSource, the factory tries to read the table's primary key via JDBC metadata. On SQLException it logs this warning and proceeds creating the source/table definition without a primary key, which can affect downstream ClickHouse table creation and split handling.
Source
Thrown at seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceFactory.java:133
tablePath.getDatabaseName(),
tablePath.getTableName()))
.executeAndWait()) {
// Query primary key
Optional<PrimaryKey> primaryKey = Optional.empty();
try {
primaryKey =
proxy.getPrimaryKey(
tablePath.getDatabaseName(), tablePath.getTableName());
log.info(
"ClickhouseSourceFactory: queried primary key for table {}.{}: {}",
tablePath.getDatabaseName(),
tablePath.getTableName(),
primaryKey.isPresent()
? primaryKey.get().getColumnNames()
: "NOT FOUND");
} catch (SQLException e) {
log.warn(
"Failed to get primary key for table {}.{}, will create table without primary key",
tablePath.getDatabaseName(),
tablePath.getTableName(),
e);
}
TableSchema.Builder builder = TableSchema.builder();
// Add primary key if exists
primaryKey.ifPresent(
pk -> {
builder.primaryKey(pk);
log.debug(
"ClickhouseSourceFactory: added primary key to TableSchema: {}",
pk.getColumnNames());
});
List<ClickHouseColumn> columns = response.getColumns();View on GitHub (pinned to cf67b549a7)
Solutions
- Check the SQLException cause in the log (permission vs connectivity) and grant the user metadata access or fix connectivity.
- Ensure the ClickHouse table exists and has an expected primary/order key; create it beforehand if needed.
- If no primary key is genuinely desired, this warning is benign — the source proceeds without one; be aware of duplicate-row risk in the sink.
Defensive patterns
Strategy: validation
Validate before calling
// pre-check primary key availability
try (ResultSet rs = conn.getMetaData().getPrimaryKeys(null, database, table)) {
if (!rs.next()) log.warn("no primary key for {}.{}", database, table);
} Try / catch
try {
primaryKey = catalog.getPrimaryKey(tablePath);
} catch (SQLException e) {
// accept no-primary-key fallback, or fail fast if PK required
} Prevention
- Grant metadata privileges to the source user
- Create tables with explicit primary keys before running the source
- Check this warning early in job logs when relying on PK semantics
When it happens
Trigger: createSource invokes catalog/table metadata retrieval and getPrimaryKey-like JDBC calls throw SQLException (table absent, connection issue, insufficient privileges).
Common situations: DB user lacking metadata read privileges; transient connection failure to ClickHouse; querying a view or table without a real primary key on older ClickHouse versions.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- GET_PRIMARY_KEY_FAILED
- Exactly once is enabled, but not found primary key or unique
- Error reading default database charsets: ${e.getMessage()}
- Failed getting table %s
- COMMON_SQL_OPERATION_FAILED
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/aa172badabd69669.
Report an issue: GitHub.