apache/seatunnel · error · CatalogException
Failed to truncate BigQuery table:
Error message
Failed to truncate BigQuery table:
What it means
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.
Source
Thrown at seatunnel-connectors-v2/connector-bigquery/src/main/java/org/apache/seatunnel/connectors/bigquery/catalog/BigQueryCatalog.java:376
if (!tableExists(tablePath)) {
if (ignoreIfNotExists) {
return;
}
throw new TableNotExistException(catalogName, tablePath);
}
String query =
String.format(
"TRUNCATE TABLE `%s.%s` ;",
getDatasetName(tablePath), tablePath.getTableName());
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
try {
bigquery.query(queryConfig);
log.info("BigQuery Table '{}' truncated successfully.", tablePath.getFullName());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CatalogException("Truncate table interrupted", e);
} catch (Exception e) {
throw new CatalogException(
"Failed to truncate BigQuery table: " + tablePath.getFullName(), e);
}
}
@Override
public boolean isExistsData(TablePath tablePath) {
if (!tableExists(tablePath)) {
return false;
}
String query =
String.format(
"SELECT 1 FROM `%s.%s` LIMIT 1 ;",
getDatasetName(tablePath), tablePath.getTableName());
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
try {
return bigquery.query(queryConfig).iterateAll().iterator().hasNext();
} catch (Exception e) {
log.warn(View on GitHub (pinned to cf67b549a7)
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
Example fix
// before
bigquery.query(QueryJobConfiguration.newBuilder("TRUNCATE TABLE " + fullName).build());
// after
Table table = bigquery.getTable(dataset, tableName);
if (table != null) {
bigquery.query(QueryJobConfiguration.newBuilder("TRUNCATE TABLE " + fullName).build());
} Defensive patterns
Strategy: validation
Validate before calling
if (!catalog.tableExists(tablePath)) {
LOG.warn("Table " + tablePath.getFullName() + " does not exist; skipping truncate");
return;
}
catalog.truncateTable(tablePath, false); Try / catch
try {
catalog.truncateTable(tablePath, false);
} catch (CatalogException e) {
Throwable cause = e.getCause();
LOG.error("Truncate failed: " + (cause == null ? e : cause.getMessage()), e);
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
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
- Failed to execute custom SQL
- Failed to create BigQuery dataset:
- Failed to drop BigQuery dataset:
- Truncate table interrupted
- Truncate table failed
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/b7e9a9802fae4d05.
Report an issue: GitHub.