Skip to content

Commit 8b7e67e

Browse files
authored
Merge pull request GoogleCloudPlatform#619 from GoogleCloudPlatform/tswast-bq-update
BigQuery update dependencies
2 parents 4b3c3d2 + 1988cae commit 8b7e67e

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

bigquery/cloud-client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.google.cloud</groupId>
3939
<artifactId>google-cloud-bigquery</artifactId>
40-
<version>0.12.0-beta</version>
40+
<version>0.13.0-beta</version>
4141
</dependency>
4242
<dependency>
4343
<groupId>commons-cli</groupId>

bigquery/cloud-client/src/main/java/com/example/bigquery/QueryParametersSample.java

+28-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import java.io.IOException;
3232
import java.util.Arrays;
33-
import java.util.Iterator;
3433
import java.util.List;
3534

3635
/** A sample that demonstrates use of query parameters. */
@@ -141,6 +140,7 @@ private static void runNamed(final String corpus, final long minWordCount)
141140
response = bigquery.getQueryResults(response.getJobId());
142141
}
143142

143+
// Check for errors.
144144
if (response.hasErrors()) {
145145
String firstError = "";
146146
if (response.getExecutionErrors().size() != 0) {
@@ -149,12 +149,14 @@ private static void runNamed(final String corpus, final long minWordCount)
149149
throw new RuntimeException(firstError);
150150
}
151151

152+
// Print all pages of the results.
152153
QueryResult result = response.getResult();
153-
Iterator<List<FieldValue>> iter = result.iterateAll();
154+
while (result != null) {
155+
for (List<FieldValue> row : result.iterateAll()) {
156+
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
157+
}
154158

155-
while (iter.hasNext()) {
156-
List<FieldValue> row = iter.next();
157-
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
159+
result = result.getNextPage();
158160
}
159161
}
160162
// [END bigquery_query_params]
@@ -193,6 +195,7 @@ private static void runArray(String gender, String[] states) throws InterruptedE
193195
response = bigquery.getQueryResults(response.getJobId());
194196
}
195197

198+
// Check for errors.
196199
if (response.hasErrors()) {
197200
String firstError = "";
198201
if (response.getExecutionErrors().size() != 0) {
@@ -201,12 +204,14 @@ private static void runArray(String gender, String[] states) throws InterruptedE
201204
throw new RuntimeException(firstError);
202205
}
203206

207+
// Print all pages of the results.
204208
QueryResult result = response.getResult();
205-
Iterator<List<FieldValue>> iter = result.iterateAll();
209+
while (result != null) {
210+
for (List<FieldValue> row : result.iterateAll()) {
211+
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
212+
}
206213

207-
while (iter.hasNext()) {
208-
List<FieldValue> row = iter.next();
209-
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
214+
result = result.getNextPage();
210215
}
211216
}
212217
// [END bigquery_query_params_arrays]
@@ -240,6 +245,7 @@ private static void runTimestamp() throws InterruptedException {
240245
response = bigquery.getQueryResults(response.getJobId());
241246
}
242247

248+
// Check for errors.
243249
if (response.hasErrors()) {
244250
String firstError = "";
245251
if (response.getExecutionErrors().size() != 0) {
@@ -248,19 +254,21 @@ private static void runTimestamp() throws InterruptedException {
248254
throw new RuntimeException(firstError);
249255
}
250256

257+
// Print all pages of the results.
251258
QueryResult result = response.getResult();
252-
Iterator<List<FieldValue>> iter = result.iterateAll();
253-
254259
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
255-
while (iter.hasNext()) {
256-
List<FieldValue> row = iter.next();
257-
System.out.printf(
258-
"%s\n",
259-
formatter.print(
260-
new DateTime(
261-
// Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC,
262-
// but org.joda.time.DateTime constructor accepts times in milliseconds.
263-
row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC)));
260+
while (result != null) {
261+
for (List<FieldValue> row : result.iterateAll()) {
262+
System.out.printf(
263+
"%s\n",
264+
formatter.print(
265+
new DateTime(
266+
// Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC,
267+
// but org.joda.time.DateTime constructor accepts times in milliseconds.
268+
row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC)));
269+
}
270+
271+
result = result.getNextPage();
264272
}
265273
}
266274
// [END bigquery_query_params_timestamps]

bigquery/cloud-client/src/main/java/com/example/bigquery/QuerySample.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.commons.cli.ParseException;
3636

3737
import java.io.IOException;
38-
import java.util.Iterator;
3938
import java.util.List;
4039
import java.util.UUID;
4140
import java.util.concurrent.TimeoutException;
@@ -144,17 +143,7 @@ public static void runQuery(QueryJobConfiguration queryConfig)
144143

145144
// Print all pages of the results.
146145
while (result != null) {
147-
if (response.hasErrors()) {
148-
String firstError = "";
149-
if (response.getExecutionErrors().size() != 0) {
150-
firstError = response.getExecutionErrors().get(0).getMessage();
151-
}
152-
throw new RuntimeException(firstError);
153-
}
154-
155-
Iterator<List<FieldValue>> iter = result.iterateAll();
156-
while (iter.hasNext()) {
157-
List<FieldValue> row = iter.next();
146+
for (List<FieldValue> row : result.iterateAll()) {
158147
for (FieldValue val : row) {
159148
System.out.printf("%s,", val.toString());
160149
}

bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.cloud.bigquery.QueryResponse;
2929
import com.google.cloud.bigquery.QueryResult;
3030

31-
import java.util.Iterator;
3231
import java.util.List;
3332
import java.util.UUID;
3433
// [END create_client]
@@ -73,11 +72,9 @@ public static void main(String... args) throws Exception {
7372
// [START print_results]
7473
QueryResult result = response.getResult();
7574

75+
// Print all pages of the results.
7676
while (result != null) {
77-
Iterator<List<FieldValue>> iter = result.iterateAll();
78-
79-
while (iter.hasNext()) {
80-
List<FieldValue> row = iter.next();
77+
for (List<FieldValue> row : result.iterateAll()) {
8178
List<FieldValue> titles = row.get(0).getRepeatedValue();
8279
System.out.println("titles:");
8380

0 commit comments

Comments
 (0)