{"record":{"id":"aa172badabd69669","repo":"apache/seatunnel","slug":"failed-to-get-primary-key-for-table-will-cr","errorCode":null,"errorMessage":"Failed to get primary key for table {}.{}, will create table without primary key","messagePattern":"Failed to get primary key for table (.+?)\\.(.+?), will create table without primary key","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceFactory.java","lineNumber":133,"sourceCode":"                                                    tablePath.getDatabaseName(),\n                                                    tablePath.getTableName()))\n                                    .executeAndWait()) {\n\n                // Query primary key\n                Optional<PrimaryKey> primaryKey = Optional.empty();\n                try {\n                    primaryKey =\n                            proxy.getPrimaryKey(\n                                    tablePath.getDatabaseName(), tablePath.getTableName());\n                    log.info(\n                            \"ClickhouseSourceFactory: queried primary key for table {}.{}: {}\",\n                            tablePath.getDatabaseName(),\n                            tablePath.getTableName(),\n                            primaryKey.isPresent()\n                                    ? primaryKey.get().getColumnNames()\n                                    : \"NOT FOUND\");\n                } catch (SQLException e) {\n                    log.warn(\n                            \"Failed to get primary key for table {}.{}, will create table without primary key\",\n                            tablePath.getDatabaseName(),\n                            tablePath.getTableName(),\n                            e);\n                }\n\n                TableSchema.Builder builder = TableSchema.builder();\n\n                // Add primary key if exists\n                primaryKey.ifPresent(\n                        pk -> {\n                            builder.primaryKey(pk);\n                            log.debug(\n                                    \"ClickhouseSourceFactory: added primary key to TableSchema: {}\",\n                                    pk.getColumnNames());\n                        });\n\n                List<ClickHouseColumn> columns = response.getColumns();","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceFactory.java#L115-L151","documentation":"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.","triggerScenarios":"createSource invokes catalog/table metadata retrieval and getPrimaryKey-like JDBC calls throw SQLException (table absent, connection issue, insufficient privileges).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-check primary key availability\ntry (ResultSet rs = conn.getMetaData().getPrimaryKeys(null, database, table)) {\n    if (!rs.next()) log.warn(\"no primary key for {}.{}\", database, table);\n}","typeGuard":null,"tryCatchPattern":"try {\n    primaryKey = catalog.getPrimaryKey(tablePath);\n} catch (SQLException e) {\n    // accept no-primary-key fallback, or fail fast if PK required\n}","preventionTips":["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"],"tags":["clickhouse","jdbc","metadata","primary-key"],"backgroundTag":"resource-not-found","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}