use of com.google.cloud.bigquery.JobId in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method getJobFromId.
/**
* Example of getting a job.
*/
// [TARGET getJob(JobId, JobOption...)]
// [VARIABLE "my_job_name"]
public Job getJobFromId(String jobName) {
// [START getJobFromId]
JobId jobIdObject = JobId.of(jobName);
Job job = bigquery.getJob(jobIdObject);
if (job == null) {
// job was not found
}
// [END getJobFromId]
return job;
}
use of com.google.cloud.bigquery.JobId in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method cancelJobFromId.
/**
* Example of cancelling a job.
*/
// [TARGET cancel(JobId)]
// [VARIABLE "my_job_name"]
public boolean cancelJobFromId(String jobName) {
// [START cancelJobFromId]
JobId jobId = JobId.of(jobName);
boolean success = bigquery.cancel(jobId);
if (success) {
// job was cancelled
} else {
// job was not found
}
// [END cancelJobFromId]
return success;
}
use of com.google.cloud.bigquery.JobId in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQuerySnippets method testJob.
@Test
public void testJob() throws ExecutionException, InterruptedException {
Job job1 = bigquerySnippets.createJob(QUERY);
Job job2 = bigquerySnippets.createJob(QUERY);
assertNotNull(job1);
assertNotNull(job2);
assertEquals(job1.getJobId(), bigquerySnippets.getJob(job1.getJobId().getJob()).getJobId());
assertEquals(job2.getJobId(), bigquerySnippets.getJobFromId(job2.getJobId().getJob()).getJobId());
Set<JobId> jobs = Sets.newHashSet(Iterators.transform(bigquerySnippets.listJobs().iterateAll().iterator(), TO_JOB_ID_FUNCTION));
while (!jobs.contains(job1.getJobId()) || !jobs.contains(job2.getJobId())) {
Thread.sleep(500);
jobs = Sets.newHashSet(Iterators.transform(bigquerySnippets.listJobs().iterateAll().iterator(), TO_JOB_ID_FUNCTION));
}
assertTrue(bigquerySnippets.cancelJob(job1.getJobId().getJob()));
assertTrue(bigquerySnippets.cancelJobFromId(job2.getJobId().getJob()));
}