use of com.google.cloud.bigquery.QueryResult in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQuerySnippets method testRunQuery.
@Test
public void testRunQuery() throws InterruptedException {
QueryResponse queryResponse = bigquerySnippets.runQuery(QUERY);
assertNotNull(queryResponse);
assertTrue(queryResponse.jobCompleted());
assertFalse(queryResponse.hasErrors());
QueryResult result = queryResponse.getResult();
assertNotNull(result);
assertTrue(bigquerySnippets.cancelJob(queryResponse.getJobId().getJob()));
queryResponse = bigquerySnippets.queryResults(QUERY);
assertNotNull(queryResponse);
assertTrue(queryResponse.jobCompleted());
assertFalse(queryResponse.hasErrors());
result = queryResponse.getResult();
assertNotNull(result);
assertTrue(bigquerySnippets.cancelJobFromId(queryResponse.getJobId().getJob()));
}
use of com.google.cloud.bigquery.QueryResult in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method runQueryWithParameters.
/**
* Example of running a query with query parameters.
*/
// [TARGET query(QueryRequest)]
// [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount"]
public QueryResponse runQueryWithParameters(String query) throws InterruptedException {
// [START runQueryWithParameters]
QueryRequest request = QueryRequest.newBuilder(query).setUseLegacySql(// standard SQL is required to use query parameters
false).addNamedParameter("wordCount", QueryParameterValue.int64(5)).build();
QueryResponse response = bigquery.query(request);
// Wait for things to finish
while (!response.jobCompleted()) {
Thread.sleep(1000);
response = bigquery.getQueryResults(response.getJobId());
}
if (response.hasErrors()) {
// handle errors
}
QueryResult result = response.getResult();
for (List<FieldValue> row : result.iterateAll()) {
// do something with the data
}
// [END runQueryWithParameters]
return response;
}
use of com.google.cloud.bigquery.QueryResult in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method queryResults.
/**
* Example of getting the results of query.
*/
// [TARGET getQueryResults(JobId, QueryResultsOption...)]
// [VARIABLE "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"]
public QueryResponse queryResults(final String query) throws InterruptedException {
// [START queryResults]
QueryRequest request = QueryRequest.of(query);
QueryResponse response = bigquery.query(request);
// Wait for things to finish
while (!response.jobCompleted()) {
Thread.sleep(1000);
response = bigquery.getQueryResults(response.getJobId());
}
if (response.hasErrors()) {
// handle errors
}
QueryResult result = response.getResult();
for (List<FieldValue> row : result.iterateAll()) {
// do something with the data
}
// [END queryResults]
return response;
}
use of com.google.cloud.bigquery.QueryResult in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method runQuery.
/**
* Example of running a query.
*/
// [TARGET query(QueryRequest)]
// [VARIABLE "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"]
public QueryResponse runQuery(String query) throws InterruptedException {
// [START runQuery]
QueryRequest request = QueryRequest.of(query);
QueryResponse response = bigquery.query(request);
// Wait for things to finish
while (!response.jobCompleted()) {
Thread.sleep(1000);
response = bigquery.getQueryResults(response.getJobId());
}
if (response.hasErrors()) {
// handle errors
}
QueryResult result = response.getResult();
for (List<FieldValue> row : result.iterateAll()) {
// do something with the data
}
// [END runQuery]
return response;
}
use of com.google.cloud.bigquery.QueryResult in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQuerySnippets method testRunQueryWithParameters.
@Test
public void testRunQueryWithParameters() throws InterruptedException {
QueryResponse queryResponse = bigquerySnippets.runQueryWithParameters(QUERY_WITH_PARAMETERS);
assertNotNull(queryResponse);
assertTrue(queryResponse.jobCompleted());
assertFalse(queryResponse.hasErrors());
QueryResult result = queryResponse.getResult();
assertNotNull(result);
assertTrue(bigquerySnippets.cancelJob(queryResponse.getJobId().getJob()));
}
Aggregations