Skip to content

Commit 005689f

Browse files
author
Bill Prin
committed
Fix SyncQuerySample
1 parent 78daa80 commit 005689f

File tree

1 file changed

+52
-36
lines changed

1 file changed

+52
-36
lines changed
Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*
2-
Copyright 2015, Google, Inc.
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
2+
Copyright 2015, Google, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515
package com.google.cloud.bigquery.samples;
@@ -24,58 +24,74 @@
2424
import java.util.Iterator;
2525
import java.util.Scanner;
2626
/**
27-
* TODO: Insert description here. (generated by elibixby)
27+
* Runs a synchronous query against Bigtable.
2828
*/
29-
public class SyncQuerySample extends BigqueryUtils{
29+
public class SyncQuerySample {
30+
3031

32+
/**
33+
* Protected because this is a collection of static methods.
34+
*/
35+
protected SyncQuerySample() {
36+
37+
}
3138

3239
//[START main]
3340
/**
34-
* @param args
35-
* @throws IOException
41+
* @param args args
42+
* @throws IOException ioexceptino
3643
*/
37-
public static void main(String[] args)
38-
throws IOException{
39-
40-
44+
public static void main(final String[] args)
45+
throws IOException {
4146
Scanner scanner = new Scanner(System.in);
4247
System.out.println("Enter your project id: ");
4348
String projectId = scanner.nextLine();
4449
System.out.println("Enter your query string: ");
4550
String queryString = scanner.nextLine();
46-
System.out.println("Enter how long to wait for the query to complete (in milliseconds):\n " +
47-
"(if longer than 10 seconds, use an asynchronous query)");
51+
System.out.println("Enter how long to wait for the query to complete"
52+
+ " (in milliseconds):\n "
53+
+ "(if longer than 10 seconds, use an asynchronous query)");
4854
long waitTime = scanner.nextLong();
4955
scanner.close();
50-
Iterator<GetQueryResultsResponse> pages = run(projectId, queryString, waitTime);
51-
while(pages.hasNext()){
52-
printRows(pages.next().getRows(), System.out);
56+
Iterator<GetQueryResultsResponse> pages = run(projectId, queryString,
57+
waitTime);
58+
while (pages.hasNext()) {
59+
BigqueryUtils.printRows(pages.next().getRows(), System.out);
5360
}
5461
}
5562
// [END main]
56-
5763

64+
65+
/**
66+
*
67+
* @param projectId project id from developer console
68+
* @param queryString query to run
69+
* @param waitTime Timeout in milliseconds before we abort
70+
* @return Iterator that pages through the results of the query
71+
* @throws IOException ioexception
72+
*/
5873
// [START run]
59-
public static Iterator<GetQueryResultsResponse> run(String projectId,
60-
String queryString,
61-
long waitTime) throws IOException{
74+
public static Iterator<GetQueryResultsResponse> run(final String projectId,
75+
final String queryString,
76+
final long waitTime) throws IOException {
6277
Bigquery bigquery = BigqueryServiceFactory.getService();
6378
//Wait until query is done with 10 second timeout, at most 5 retries on error
6479
QueryResponse query = bigquery.jobs().query(
6580
projectId,
66-
new QueryRequest().setTimeoutMs(waitTime).setQuery(queryString)).execute();
67-
68-
//Make a request to get the results of the query
81+
new QueryRequest().setTimeoutMs(waitTime).setQuery(queryString))
82+
.execute();
83+
84+
//Make a request to get the results of the query
6985
//(timeout is zero since job should be complete)
70-
86+
7187
GetQueryResults getRequest = bigquery.jobs().getQueryResults(
7288
query.getJobReference().getProjectId(),
7389
query.getJobReference().getJobId());
74-
75-
76-
return getPages(getRequest);
90+
91+
92+
return BigqueryUtils.getPages(getRequest);
7793
}
7894
// [END run]
79-
95+
8096

8197
}

0 commit comments

Comments
 (0)