Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Java 7 for BQ samples. #586

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bigquery/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</parent>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
* A sample that demonstrates use of query parameters.
Expand Down Expand Up @@ -150,12 +149,11 @@ private static void runNamed(final String corpus, final long minWordCount)
}

if (response.hasErrors()) {
throw new RuntimeException(
response
.getExecutionErrors()
.stream()
.<String>map(err -> err.getMessage())
.collect(Collectors.joining("\n")));
String firstError = "";
if (response.getExecutionErrors().size() != 0) {
firstError = response.getExecutionErrors().get(0).getMessage();
}
throw new RuntimeException(firstError);
}

QueryResult result = response.getResult();
Expand Down Expand Up @@ -208,12 +206,11 @@ private static void runArray(String gender, String[] states)
}

if (response.hasErrors()) {
throw new RuntimeException(
response
.getExecutionErrors()
.stream()
.<String>map(err -> err.getMessage())
.collect(Collectors.joining("\n")));
String firstError = "";
if (response.getExecutionErrors().size() != 0) {
firstError = response.getExecutionErrors().get(0).getMessage();
}
throw new RuntimeException(firstError);
}

QueryResult result = response.getResult();
Expand Down Expand Up @@ -256,12 +253,11 @@ private static void runTimestamp() throws InterruptedException {
}

if (response.hasErrors()) {
throw new RuntimeException(
response
.getExecutionErrors()
.stream()
.<String>map(err -> err.getMessage())
.collect(Collectors.joining("\n")));
String firstError = "";
if (response.getExecutionErrors().size() != 0) {
firstError = response.getExecutionErrors().get(0).getMessage();
}
throw new RuntimeException(firstError);
}

QueryResult result = response.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Runs a synchronous query against BigQuery.
Expand All @@ -40,7 +39,7 @@ public class SyncQuerySample {
/**
* Prompts the user for the required parameters to perform a query.
*/
public static void main(final String[] args) throws IOException {
public static void main(final String[] args) throws IOException, InterruptedException {
String queryString = System.getProperty("query");
if (queryString == null || queryString.isEmpty()) {
System.out.println("The query property was not set, using default.");
Expand Down Expand Up @@ -82,7 +81,7 @@ public static void run(
final PrintStream out,
final String queryString,
final long waitTime,
final boolean useLegacySql) throws IOException {
final boolean useLegacySql) throws IOException, InterruptedException {
BigQuery bigquery =
new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());

Expand All @@ -95,20 +94,28 @@ public static void run(
.build();
QueryResponse response = bigquery.query(queryRequest);

// Wait for the job to finish (if the query takes more than 10 seconds to complete).
while (!response.jobCompleted()) {
Thread.sleep(1000);
response = bigquery.getQueryResults(response.getJobId());
}

if (response.hasErrors()) {
throw new RuntimeException(
response
.getExecutionErrors()
.stream()
.<String>map(err -> err.getMessage())
.collect(Collectors.joining("\n")));
String firstError = "";
if (response.getExecutionErrors().size() != 0) {
firstError = response.getExecutionErrors().get(0).getMessage();
}
throw new RuntimeException(firstError);
}

QueryResult result = response.getResult();
Iterator<List<FieldValue>> iter = result.iterateAll();
while (iter.hasNext()) {
List<FieldValue> row = iter.next();
out.println(row.stream().map(val -> val.toString()).collect(Collectors.joining(",")));
for (FieldValue val : row) {
out.printf("%s,", val.toString());
}
out.printf("\n");
}
}
// [END run]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.junit.runners.JUnit4;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
Expand All @@ -43,7 +42,7 @@ public void setUp() {
}

@Test
public void testSyncQuery() throws IOException {
public void testSyncQuery() throws Exception {
SyncQuerySample.run(
out,
"SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;",
Expand All @@ -55,7 +54,7 @@ public void testSyncQuery() throws IOException {
}

@Test
public void testSyncQueryLegacySql() throws IOException {
public void testSyncQueryLegacySql() throws Exception {
SyncQuerySample.run(
out,
"SELECT corpus FROM [publicdata:samples.shakespeare] GROUP BY corpus;",
Expand Down