-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BigQuery snippets for Job.isDone().
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* EDITING INSTRUCTIONS | ||
* This file is referenced in Job's javadoc. Any change to this file should be reflected in | ||
* Job's javadoc. | ||
*/ | ||
|
||
package com.google.cloud.examples.bigquery.snippets; | ||
|
||
import com.google.cloud.bigquery.Job; | ||
|
||
public class JobSnippets { | ||
|
||
private final Job job; | ||
|
||
public JobSnippets(Job job) { | ||
this.job = job; | ||
} | ||
|
||
/** | ||
* Example of waiting for a job until it reports that it is done. | ||
*/ | ||
// [TARGET isDone()] | ||
public boolean isDone() { | ||
try { | ||
// [START isDone] | ||
while(!job.isDone()) { | ||
Thread.sleep(1000L); | ||
} | ||
// [END isDone] | ||
} catch (InterruptedException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...oud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITJobSnippets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.examples.bigquery.snippets; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.google.cloud.bigquery.BigQuery; | ||
import com.google.cloud.bigquery.BigQueryOptions; | ||
|
||
import com.google.cloud.bigquery.Job; | ||
import com.google.cloud.bigquery.JobConfiguration; | ||
import com.google.cloud.bigquery.JobInfo; | ||
import com.google.cloud.bigquery.QueryJobConfiguration; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class ITJobSnippets { | ||
private static BigQuery bigQuery; | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
bigQuery = BigQueryOptions.defaultInstance().service(); | ||
} | ||
|
||
@Test | ||
public void testIsDone() throws Exception { | ||
JobConfiguration jobConfig = | ||
QueryJobConfiguration | ||
.builder("SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;") | ||
.useLegacySql(false) | ||
.build(); | ||
JobInfo jobInfo = JobInfo.builder(jobConfig).build(); | ||
Job job = bigQuery.create(jobInfo); | ||
JobSnippets jobSnippets = new JobSnippets(job); | ||
boolean result = jobSnippets.isDone(); | ||
assertTrue(result); | ||
} | ||
} |