Skip to content

Commit 85f218d

Browse files
committed
Add BigQuery snippets for Job.isDone().
1 parent 3c62510 commit 85f218d

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* EDITING INSTRUCTIONS
19+
* This file is referenced in Job's javadoc. Any change to this file should be reflected in
20+
* Job's javadoc.
21+
*/
22+
23+
package com.google.cloud.examples.bigquery.snippets;
24+
25+
import com.google.cloud.bigquery.Job;
26+
27+
public class JobSnippets {
28+
29+
private final Job job;
30+
31+
public JobSnippets(Job job) {
32+
this.job = job;
33+
}
34+
35+
/**
36+
* Example of waiting for a job until it reports that it is done.
37+
*/
38+
// [TARGET isDone()]
39+
public boolean isDone() {
40+
try {
41+
// [START isDone]
42+
while(!job.isDone()) {
43+
Thread.sleep(1000L);
44+
}
45+
// [END isDone]
46+
} catch (InterruptedException e) {
47+
return false;
48+
}
49+
return true;
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.examples.bigquery.snippets;
18+
19+
import static org.junit.Assert.assertTrue;
20+
21+
import com.google.cloud.bigquery.BigQuery;
22+
import com.google.cloud.bigquery.BigQueryOptions;
23+
24+
import com.google.cloud.bigquery.Job;
25+
import com.google.cloud.bigquery.JobConfiguration;
26+
import com.google.cloud.bigquery.JobInfo;
27+
import com.google.cloud.bigquery.QueryJobConfiguration;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
31+
public class ITJobSnippets {
32+
private static BigQuery bigQuery;
33+
34+
@BeforeClass
35+
public static void beforeClass() {
36+
bigQuery = BigQueryOptions.defaultInstance().service();
37+
}
38+
39+
@Test
40+
public void testIsDone() throws Exception {
41+
JobConfiguration jobConfig =
42+
QueryJobConfiguration
43+
.builder("SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;")
44+
.useLegacySql(false)
45+
.build();
46+
JobInfo jobInfo = JobInfo.builder(jobConfig).build();
47+
Job job = bigQuery.create(jobInfo);
48+
JobSnippets jobSnippets = new JobSnippets(job);
49+
boolean result = jobSnippets.isDone();
50+
assertTrue(result);
51+
}
52+
}

0 commit comments

Comments
 (0)