{"record":{"id":"d1b8dd270cb0f40a","repo":"apache/seatunnel","slug":"truncate-table-failed","errorCode":null,"errorMessage":"Truncate table failed","messagePattern":"Truncate table failed","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/catalog/ClickhouseCatalog.java","lineNumber":169,"sourceCode":"                table.getComment(),\n                table.getTableSchema());\n    }\n\n    @Override\n    public void dropTable(TablePath tablePath, boolean ignoreIfNotExists)\n            throws TableNotExistException, CatalogException {\n        proxy.dropTable(tablePath, ignoreIfNotExists);\n    }\n\n    @Override\n    public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)\n            throws TableNotExistException, CatalogException {\n        try {\n            if (tableExists(tablePath)) {\n                proxy.truncateTable(tablePath, ignoreIfNotExists);\n            }\n        } catch (Exception e) {\n            throw new CatalogException(\"Truncate table failed\", e);\n        }\n    }\n\n    @Override\n    public void executeSql(TablePath tablePath, String sql) {\n        try {\n            proxy.executeSql(sql);\n        } catch (Exception e) {\n            throw new CatalogException(String.format(\"Failed EXECUTE SQL in catalog %s\", sql), e);\n        }\n    }\n\n    @Override\n    public boolean isExistsData(TablePath tablePath) {\n        try {\n            return proxy.isExistsData(tablePath.getFullName());\n        } catch (ExecutionException | InterruptedException e) {\n            throw new RuntimeException(e);","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/catalog/ClickhouseCatalog.java#L151-L187","documentation":"ClickhouseCatalog.truncateTable deletes all rows of the target table via the proxy client when the table exists. Any failure (connection error, insufficient rights, unsupported table engine) is wrapped in a CatalogException with the message 'Truncate table failed'. Unlike other methods, the message omits the table name, so the cause chain carries the details.","triggerScenarios":"Calling truncateTable(tablePath, ignoreIfNotExists) when ClickHouse rejects the TRUNCATE statement: read-only user, non-truncatable engine (e.g. Distributed without support, Memory quirks), or the proxy call itself fails mid-request.","commonSituations":"User lacking ALTER/TRUNCATE privilege on the table; truncating a Distributed table where underlying local tables reject the operation; transient network failure to ClickHouse; table exists per check but is dropped before truncate executes.","solutions":["Check the root cause in the wrapped exception ('Caused by') for the actual ClickHouse error","Grant the ClickHouse user the privileges needed to truncate the table (ALTER/TRUNCATE) or use an admin account","If the engine does not support TRUNCATE, drop and recreate the table via executeSql instead","Verify the table still exists and is writable at execution time; handle race with tableExists"],"exampleFix":"// before\ncatalog.truncateTable(tablePath, true);\n// after\ntry {\n    catalog.truncateTable(tablePath, true);\n} catch (CatalogException e) {\n    logger.warn(\"Truncate failed for {}: {}\", tablePath.getFullName(), e.getCause());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!catalog.tableExists(tablePath)) {\n    return; // nothing to truncate\n}\n// confirm user can truncate\ncatalog.executeSql(tablePath, \"SELECT count() FROM system.grants WHERE user = currentUser() AND privilege ILIKE '%ALTER%'\");","typeGuard":null,"tryCatchPattern":"try {\n    catalog.truncateTable(tablePath, ignoreIfNotExists);\n} catch (CatalogException e) {\n    Throwable cause = e.getCause();\n    logger.error(\"Truncate table failed: {}\", cause == null ? e.getMessage() : cause.getMessage());\n    if (cause instanceof java.net.ConnectException) {\n        // retry transient failure\n    }\n    throw e;\n}","preventionTips":["Read the 'Caused by' chain; this message omits the table name","Use a ClickHouse user with ALTER/TRUNCATE privileges","Avoid truncating Distributed-table backends that reject TRUNCATE; drop/recreate instead","Re-check table existence right before truncation to handle races"],"tags":["clickhouse","catalog","truncate","sql"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}