Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.FormatOptions;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.JobId;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.LoadJobConfiguration;
import com.google.cloud.bigquery.QueryJobConfiguration;
Expand Down Expand Up @@ -177,18 +178,26 @@ public void runBatchQuery() throws TimeoutException, InterruptedException {
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(query)
// Run at batch priority, which won't count toward concurrent rate
// limit. See:
// https://cloud.google.com/bigquery/docs/running-queries#batch
// limit.
.setPriority(QueryJobConfiguration.Priority.BATCH)
.build();

// Print the results.
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
for (FieldValue val : row) {
System.out.printf("%s,", val.toString());
}
System.out.printf("\n");
}
// Location must match that of the dataset(s) referenced in the query.
JobId jobId = JobId.newBuilder().setRandomJob().setLocation("US").build();
String jobIdString = jobId.getJob();

// API request - starts the query.
bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());

// Check on the progress by getting the job's updated state. Once the state
// is `DONE`, the results are ready.
Job queryJob = bigquery.getJob(
JobId.newBuilder().setJob(jobIdString).setLocation("US").build());
System.out.printf(
"Job %s in location %s currently in state: %s%n",
queryJob.getJobId().getJob(),
queryJob.getJobId().getLocation(),
queryJob.getStatus().getState().toString());
// [END bigquery_query_batch]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void testRunUncachedQuery() throws TimeoutException, InterruptedException
public void testRunBatchQuery() throws TimeoutException, InterruptedException {
cloudSnippets.runBatchQuery();
String got = bout.toString();
assertTrue(got.contains("romeoandjuliet"));
assertTrue(got.contains("in location US currently in state:"));
}

@Test
Expand Down