Skip to content

Commit

Permalink
Merge pull request #619 from GoogleCloudPlatform/tswast-bq-update
Browse files Browse the repository at this point in the history
BigQuery update dependencies
  • Loading branch information
tswast authored Apr 18, 2017
2 parents 4b3c3d2 + 1988cae commit 8b7e67e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bigquery/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
<version>0.12.0-beta</version>
<version>0.13.0-beta</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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) {
Expand All @@ -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<List<FieldValue>> iter = result.iterateAll();
while (result != null) {
for (List<FieldValue> row : result.iterateAll()) {
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
}

while (iter.hasNext()) {
List<FieldValue> row = iter.next();
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
result = result.getNextPage();
}
}
// [END bigquery_query_params]
Expand Down Expand Up @@ -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) {
Expand All @@ -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<List<FieldValue>> iter = result.iterateAll();
while (result != null) {
for (List<FieldValue> row : result.iterateAll()) {
System.out.printf("%s: %d\n", row.get(0).getStringValue(), row.get(1).getLongValue());
}

while (iter.hasNext()) {
List<FieldValue> 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]
Expand Down Expand Up @@ -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) {
Expand All @@ -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<List<FieldValue>> iter = result.iterateAll();

DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
while (iter.hasNext()) {
List<FieldValue> 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<FieldValue> 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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<FieldValue>> iter = result.iterateAll();
while (iter.hasNext()) {
List<FieldValue> row = iter.next();
for (List<FieldValue> row : result.iterateAll()) {
for (FieldValue val : row) {
System.out.printf("%s,", val.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<List<FieldValue>> iter = result.iterateAll();

while (iter.hasNext()) {
List<FieldValue> row = iter.next();
for (List<FieldValue> row : result.iterateAll()) {
List<FieldValue> titles = row.get(0).getRepeatedValue();
System.out.println("titles:");

Expand Down

0 comments on commit 8b7e67e

Please sign in to comment.