{"record":{"id":"b7e9a9802fae4d05","repo":"apache/seatunnel","slug":"failed-to-truncate-bigquery-table","errorCode":null,"errorMessage":"Failed to truncate BigQuery table: ","messagePattern":"Failed to truncate BigQuery table: ","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-bigquery/src/main/java/org/apache/seatunnel/connectors/bigquery/catalog/BigQueryCatalog.java","lineNumber":376,"sourceCode":"        if (!tableExists(tablePath)) {\n            if (ignoreIfNotExists) {\n                return;\n            }\n            throw new TableNotExistException(catalogName, tablePath);\n        }\n        String query =\n                String.format(\n                        \"TRUNCATE TABLE `%s.%s` ;\",\n                        getDatasetName(tablePath), tablePath.getTableName());\n        QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();\n        try {\n            bigquery.query(queryConfig);\n            log.info(\"BigQuery Table '{}' truncated successfully.\", tablePath.getFullName());\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new CatalogException(\"Truncate table interrupted\", e);\n        } catch (Exception e) {\n            throw new CatalogException(\n                    \"Failed to truncate BigQuery table: \" + tablePath.getFullName(), e);\n        }\n    }\n\n    @Override\n    public boolean isExistsData(TablePath tablePath) {\n        if (!tableExists(tablePath)) {\n            return false;\n        }\n        String query =\n                String.format(\n                        \"SELECT 1 FROM `%s.%s` LIMIT 1 ;\",\n                        getDatasetName(tablePath), tablePath.getTableName());\n        QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();\n        try {\n            return bigquery.query(queryConfig).iterateAll().iterator().hasNext();\n        } catch (Exception e) {\n            log.warn(","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-bigquery/src/main/java/org/apache/seatunnel/connectors/bigquery/catalog/BigQueryCatalog.java#L358-L394","documentation":"Thrown by BigQueryCatalog.truncateTable when the bigquery.query call running the TRUNCATE TABLE statement fails with any non-interrupt exception. The message names the fully-qualified table that could not be truncated and the wrapped BigQueryException carries the real API cause.","triggerScenarios":"Calling truncateTable on a table that does not exist in BigQuery, when the service account lacks bigquery.tables.getData/deleteData and bigquery.jobs.create permissions, when the table is outside a dataset the caller can query, or on API quota/network errors while executing TRUNCATE TABLE.","commonSituations":"Save-mode 'truncate' configured against a target table not yet created in BigQuery; read-only service account; table name/dataset case-sensitivity mismatch; query quota exceeded (429); table locked by a streaming buffer (streaming inserts restrict DDL).","solutions":["Read the wrapped BigQueryException cause for the specific API error (404 table not found, 403 permission, 400 invalid query)","Confirm the table exists (catalog.tableExists) before truncating, or use ignoreIfNotExists=true semantics","Grant the service account bigquery.tables.deleteData / dataOwner permissions and bigquery.jobs.create","Check for an active streaming buffer on the table; TRUNCATE may be rejected while streaming writes are recent"],"exampleFix":"// before\nbigquery.query(QueryJobConfiguration.newBuilder(\"TRUNCATE TABLE \" + fullName).build());\n// after\nTable table = bigquery.getTable(dataset, tableName);\nif (table != null) {\n    bigquery.query(QueryJobConfiguration.newBuilder(\"TRUNCATE TABLE \" + fullName).build());\n}","handlingStrategy":"validation","validationCode":"if (!catalog.tableExists(tablePath)) {\n    LOG.warn(\"Table \" + tablePath.getFullName() + \" does not exist; skipping truncate\");\n    return;\n}\ncatalog.truncateTable(tablePath, false);","typeGuard":null,"tryCatchPattern":"try {\n    catalog.truncateTable(tablePath, false);\n} catch (CatalogException e) {\n    Throwable cause = e.getCause();\n    LOG.error(\"Truncate failed: \" + (cause == null ? e : cause.getMessage()), e);\n    throw e;\n}","preventionTips":["Verify the table exists and permissions (bigquery.tables.getData, jobs.create) before truncating","Match dataset/table names exactly (BigQuery names are case-sensitive in queries)","Avoid streaming inserts immediately before TRUNCATE (streaming buffer restrictions)","Handle 429 quota errors with backoff"],"tags":["bigquery","truncate","sql-query","catalog"],"backgroundTag":"sql-query-failed","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"}