From 1988caebc3ec62a6e064d86c9b637e825b1cd49b Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 18 Apr 2017 15:23:53 +0000 Subject: [PATCH] BigQuery update dependencies Manually fix some breaking changes caused by the PageImpl iterator->iterable. --- bigquery/cloud-client/pom.xml | 2 +- .../bigquery/QueryParametersSample.java | 48 +++++++++++-------- .../com/example/bigquery/QuerySample.java | 13 +---- .../java/com/example/bigquery/SimpleApp.java | 7 +-- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/bigquery/cloud-client/pom.xml b/bigquery/cloud-client/pom.xml index a8854a9429c..091d06a1375 100644 --- a/bigquery/cloud-client/pom.xml +++ b/bigquery/cloud-client/pom.xml @@ -37,7 +37,7 @@ com.google.cloud google-cloud-bigquery - 0.12.0-beta + 0.13.0-beta commons-cli diff --git a/bigquery/cloud-client/src/main/java/com/example/bigquery/QueryParametersSample.java b/bigquery/cloud-client/src/main/java/com/example/bigquery/QueryParametersSample.java index 2213657cc39..ba908fb2cde 100644 --- a/bigquery/cloud-client/src/main/java/com/example/bigquery/QueryParametersSample.java +++ b/bigquery/cloud-client/src/main/java/com/example/bigquery/QueryParametersSample.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.util.Arrays; -import java.util.Iterator; import java.util.List; /** A sample that demonstrates use of query parameters. */ @@ -141,6 +140,7 @@ private static void runNamed(final String corpus, final long minWordCount) response = bigquery.getQueryResults(response.getJobId()); } + // Check for errors. if (response.hasErrors()) { String firstError = ""; if (response.getExecutionErrors().size() != 0) { @@ -149,12 +149,14 @@ private static void runNamed(final String corpus, final long minWordCount) throw new RuntimeException(firstError); } + // Print all pages of the results. QueryResult result = response.getResult(); - Iterator> iter = result.iterateAll(); + while (result != null) { + for (List row : result.iterateAll()) { + System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue()); + } - while (iter.hasNext()) { - List row = iter.next(); - System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue()); + result = result.getNextPage(); } } // [END bigquery_query_params] @@ -193,6 +195,7 @@ private static void runArray(String gender, String[] states) throws InterruptedE response = bigquery.getQueryResults(response.getJobId()); } + // Check for errors. if (response.hasErrors()) { String firstError = ""; if (response.getExecutionErrors().size() != 0) { @@ -201,12 +204,14 @@ private static void runArray(String gender, String[] states) throws InterruptedE throw new RuntimeException(firstError); } + // Print all pages of the results. QueryResult result = response.getResult(); - Iterator> iter = result.iterateAll(); + while (result != null) { + for (List row : result.iterateAll()) { + System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue()); + } - while (iter.hasNext()) { - List row = iter.next(); - System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue()); + result = result.getNextPage(); } } // [END bigquery_query_params_arrays] @@ -240,6 +245,7 @@ private static void runTimestamp() throws InterruptedException { response = bigquery.getQueryResults(response.getJobId()); } + // Check for errors. if (response.hasErrors()) { String firstError = ""; if (response.getExecutionErrors().size() != 0) { @@ -248,19 +254,21 @@ private static void runTimestamp() throws InterruptedException { throw new RuntimeException(firstError); } + // Print all pages of the results. QueryResult result = response.getResult(); - Iterator> iter = result.iterateAll(); - DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(); - while (iter.hasNext()) { - List row = iter.next(); - System.out.printf( - "%s\n", - formatter.print( - new DateTime( - // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC, - // but org.joda.time.DateTime constructor accepts times in milliseconds. - row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC))); + while (result != null) { + for (List row : result.iterateAll()) { + System.out.printf( + "%s\n", + formatter.print( + new DateTime( + // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC, + // but org.joda.time.DateTime constructor accepts times in milliseconds. + row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC))); + } + + result = result.getNextPage(); } } // [END bigquery_query_params_timestamps] diff --git a/bigquery/cloud-client/src/main/java/com/example/bigquery/QuerySample.java b/bigquery/cloud-client/src/main/java/com/example/bigquery/QuerySample.java index 44d7b27e01b..c9e9438eb73 100644 --- a/bigquery/cloud-client/src/main/java/com/example/bigquery/QuerySample.java +++ b/bigquery/cloud-client/src/main/java/com/example/bigquery/QuerySample.java @@ -35,7 +35,6 @@ import org.apache.commons.cli.ParseException; import java.io.IOException; -import java.util.Iterator; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeoutException; @@ -144,17 +143,7 @@ public static void runQuery(QueryJobConfiguration queryConfig) // Print all pages of the results. while (result != null) { - if (response.hasErrors()) { - String firstError = ""; - if (response.getExecutionErrors().size() != 0) { - firstError = response.getExecutionErrors().get(0).getMessage(); - } - throw new RuntimeException(firstError); - } - - Iterator> iter = result.iterateAll(); - while (iter.hasNext()) { - List row = iter.next(); + for (List row : result.iterateAll()) { for (FieldValue val : row) { System.out.printf("%s,", val.toString()); } diff --git a/bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java b/bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java index 5984a3957d1..fb02f5ffd24 100644 --- a/bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java +++ b/bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java @@ -28,7 +28,6 @@ import com.google.cloud.bigquery.QueryResponse; import com.google.cloud.bigquery.QueryResult; -import java.util.Iterator; import java.util.List; import java.util.UUID; // [END create_client] @@ -73,11 +72,9 @@ public static void main(String... args) throws Exception { // [START print_results] QueryResult result = response.getResult(); + // Print all pages of the results. while (result != null) { - Iterator> iter = result.iterateAll(); - - while (iter.hasNext()) { - List row = iter.next(); + for (List row : result.iterateAll()) { List titles = row.get(0).getRepeatedValue(); System.out.println("titles:");