Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for jobs.delete #1387

Merged
merged 4 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions google-cloud-bigquery/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down