Skip to content
Permalink
Browse files
feat: add support for jobs.delete (#1387)
* feat: add support for jobs.delete

* update IT

* lint

* updates
  • Loading branch information
stephaniewang526 committed Jun 24, 2021
1 parent ac854c4 commit 95f1a6c2e3281d61d38660749cf31fa504ddf8e0
@@ -3,13 +3,13 @@
<differences>
<!-- TODO: REMOVE AFTER RELEASE -->
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/bigquery/ExternalTableDefinition</className>
<method>com.google.common.collect.ImmutableList getDecimalTargetTypes()</method>
<differenceType>7012</differenceType>
<className>com/google/cloud/bigquery/BigQuery</className>
<method>boolean delete(com.google.cloud.bigquery.JobId)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/bigquery/ExternalTableDefinition$Builder</className>
<method> com.google.cloud.bigquery.ExternalTableDefinition$Builder setDecimalTargetTypes(java.util.List)</method>
<differenceType>7012</differenceType>
<className>com/google/cloud/bigquery/spi/v2/BigQueryRpc</className>
<method>boolean deleteJob(java.lang.String, java.lang.String, java.lang.String)</method>
</difference>
</differences>
@@ -982,6 +982,14 @@ public int hashCode() {
*/
boolean delete(RoutineId routineId);

/**
* Deletes the requested job.
*
* @return {@code true} if job was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
*/
boolean delete(JobId jobId);

/**
* Updates dataset information.
*
@@ -585,6 +585,30 @@ public Boolean call() {
}
}

@Override
public boolean delete(JobId jobId) {
final JobId completeJobId =
jobId.setProjectId(
Strings.isNullOrEmpty(jobId.getProject())
? getOptions().getProjectId()
: jobId.getProject());
try {
return runWithRetries(
new Callable<Boolean>() {
@Override
public Boolean call() {
return bigQueryRpc.deleteJob(
completeJobId.getProject(), completeJobId.getJob(), completeJobId.getLocation());
}
},
getOptions().getRetrySettings(),
EXCEPTION_HANDLER,
getOptions().getClock());
} catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}

@Override
public Dataset update(DatasetInfo datasetInfo, DatasetOption... options) {
final com.google.api.services.bigquery.model.Dataset datasetPb =
@@ -270,6 +270,14 @@ TableDataList listTableData(
*/
boolean cancel(String projectId, String jobId, String location);

/**
* Sends a job delete request.
*
* @return {@code true} if delete was successful, {@code false} if the job was not found
* @throws BigQueryException upon failure
*/
boolean deleteJob(String projectId, String jobName, String location);

/**
* Returns results of the query associated with the provided job.
*
@@ -607,6 +607,21 @@ public boolean cancel(String projectId, String jobId, String location) {
}
}

@Override
public boolean deleteJob(String projectId, String jobName, String location) {
try {
bigquery
.jobs()
.delete(projectId, jobName)
.setLocation(location)
.setPrettyPrint(false)
.execute();
return true;
} catch (IOException ex) {
throw translate(ex);
}
}

@Override
public GetQueryResultsResponse getQueryResults(
String projectId, String jobId, String location, Map<Option, ?> options) {
@@ -1243,6 +1243,20 @@ public void testDeleteNonExistingTable() {
assertFalse(bigquery.delete("test_delete_non_existing_table"));
}

@Test
public void testDeleteJob() {
String query = "SELECT 17 as foo";
QueryJobConfiguration config = QueryJobConfiguration.of(query);
String jobName = "jobId_" + UUID.randomUUID().toString();
JobId jobId =
JobId.newBuilder().setLocation("us-east1").setJob(jobName).setProject(PROJECT_ID).build();
Job createdJob = bigquery.create(JobInfo.of(jobId, config));
Job remoteJob = bigquery.getJob(createdJob.getJobId());
assertEquals(createdJob.getJobId(), remoteJob.getJobId());
assertTrue(bigquery.delete(jobId));
assertNull(bigquery.getJob(jobId));
}

@Test
public void testInsertAll() throws IOException {
String tableName = "test_insert_all_table";

0 comments on commit 95f1a6c

Please sign in to comment.