我通过执行此处描述的 queryJob 来截断我的表:https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries
"truncate table " + PROJECT_ID + "." + datasetName + "." + tableName;
我等到工作完成
queryJob = queryJob.waitFor();
截断效果很好。
无论如何,如果我在截断操作之后立即进行插入
InsertAllResponse response = table.insert(rows);
它导致
com.google.cloud.bigquery.BigQueryException: Table is truncated.
具有以下日志:
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
POST https://www.googleapis.com/bigquery/v2/projects/[MYPROJECTID]/datasets/[MYDATASET]/tables/[MYTABLE]/insertAll?prettyPrint=false
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Table is truncated.",
"reason" : "notFound"
} ],
"message" : "Table is truncated.",
"status" : "NOT_FOUND"
}
有时我什至需要在截断和插入之间等待超过 5 分钟。
我想检查我的表是否仍处于“表已截断”状态。周期性地直到这种状态消失。
我如何请求 bigquery api 来检查表是否准备好插入?
我如何请求bigquery api来获取表的状态?
Edit
可以找到重现的示例here https://github.com/daveyx/bigquery-truncate-404