在使用Java BigQuery API执行更新操作时,可以通过execute()
方法获取UpdateTableResult
对象,该对象包含了更新的行数
import com.google.cloud.bigquery.*;
public class BigqueryUpdateExample {
public static void main(String[] args) {
String projectId = "your_project_id";
String datasetId = "your_dataset_id";
String tableId = "your_table_id";
BigQuery bigquery = BigQueryOptions.newBuilder().setProjectId(projectId).build().getService();
// 构建更新语句
TableId table = TableId.of(datasetId, tableId);
UpdateTableRequest updateRequest = UpdateTableRequest.newBuilder()
.setTable(table)
.setSchema(new TableSchema().setFields(Arrays.asList(
Field.of("id", StandardSQLTypeName.INTEGER),
Field.of("name", StandardSQLTypeName.STRING),
Field.of("age", StandardSQLTypeName.INTEGER)
)))
.setUpdateMask(FieldMask.of("name", "age"))
.setDestinationTable(table)
.build();
// 执行更新操作
UpdateTableResult updateResult = bigquery.updateTable(updateRequest);
// 获取更新的行数
long updatedRows = updateResult.getTotalRowsUpdated();
System.out.println("Updated rows: " + updatedRows);
}
}
领取专属 10元无门槛券
手把手带您无忧上云