Search in sources :

Example 1 with JobId

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;
}
Also used : Job(com.google.cloud.bigquery.Job) JobId(com.google.cloud.bigquery.JobId)

Example 2 with JobId

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;
}
Also used : JobId(com.google.cloud.bigquery.JobId)

Example 3 with JobId

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()));
}
Also used : Job(com.google.cloud.bigquery.Job) JobId(com.google.cloud.bigquery.JobId) Test(org.junit.Test)

Aggregations

JobId (com.google.cloud.bigquery.JobId)3 Job (com.google.cloud.bigquery.Job)2 Test (org.junit.Test)1