Skip to content

Commit 600e06a

Browse files
committed
Merge pull request #35 from GoogleCloudPlatform/style
Enforce style.
2 parents 53b3a73 + 985f780 commit 600e06a

File tree

14 files changed

+234
-259
lines changed

14 files changed

+234
-259
lines changed

bigquery/pom.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@
4141
<artifactId>google-oauth-client-jetty</artifactId>
4242
<version>${project.oauth.version}</version>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.google.code.gson</groupId>
46+
<artifactId>gson</artifactId>
47+
<version>2.3.1</version>
48+
</dependency>
4449
<dependency>
4550
<groupId>junit</groupId>
4651
<artifactId>junit</artifactId>
52+
<scope>test</scope>
4753
</dependency>
4854
<dependency>
4955
<groupId>com.jcabi</groupId>
5056
<artifactId>jcabi-matchers</artifactId>
51-
</dependency>
52-
<dependency>
53-
<groupId>com.google.code.gson</groupId>
54-
<artifactId>gson</artifactId>
55-
<version>2.3.1</version>
57+
<scope>test</scope>
5658
</dependency>
5759
</dependencies>
5860

bigquery/src/main/java/com/google/cloud/bigquery/samples/AsyncQuerySample.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@
3333
* Example of authorizing with BigQuery and reading from a public dataset.
3434
*/
3535
public class AsyncQuerySample extends BigqueryUtils {
36-
37-
3836
// [START main]
3937
/**
38+
* Prompts for all the parameters required to make a query.
39+
*
4040
* @param args Command line args
4141
* @throws IOException IOException
4242
* @throws InterruptedException InterruptedException
4343
*/
4444
public static void main(final String[] args)
4545
throws IOException, InterruptedException {
46-
4746
Scanner scanner = new Scanner(System.in);
4847
System.out.println("Enter your project id: ");
4948
String projectId = scanner.nextLine();
@@ -52,20 +51,20 @@ public static void main(final String[] args)
5251
System.out.println("Run query in batch mode? [true|false] ");
5352
boolean batch = Boolean.valueOf(scanner.nextLine());
5453
System.out.println("Enter how often to check if your job is complete "
55-
+ "(milliseconds): ");
54+
+ "(milliseconds): ");
5655
long waitTime = scanner.nextLong();
5756
scanner.close();
5857
Iterator<GetQueryResultsResponse> pages = run(projectId, queryString,
59-
batch, waitTime);
58+
batch, waitTime);
6059
while (pages.hasNext()) {
6160
printRows(pages.next().getRows(), System.out);
6261
}
63-
6462
}
6563
// [END main]
66-
// [START run]
6764

65+
// [START run]
6866
/**
67+
* Run the query.
6968
*
7069
* @param projectId Get this from Google Developers console
7170
* @param queryString Query we want to run against BigQuery
@@ -75,7 +74,7 @@ public static void main(final String[] args)
7574
* @throws IOException Thrown if there's an IOException
7675
* @throws InterruptedException Thrown if there's an Interrupted Exception
7776
*/
78-
public static Iterator<GetQueryResultsResponse> run(final String projectId,
77+
public static Iterator<GetQueryResultsResponse> run(final String projectId,
7978
final String queryString,
8079
final boolean batch,
8180
final long waitTime)
@@ -94,7 +93,7 @@ public static Iterator<GetQueryResultsResponse> run(final String projectId,
9493
GetQueryResults resultsRequest = bigquery.jobs().getQueryResults(
9594
projectId, query.getJobReference().getJobId());
9695

97-
return getPages(resultsRequest);
96+
return getPages(resultsRequest);
9897
}
9998
// [END run]
10099

@@ -115,7 +114,7 @@ public static Job asyncQuery(final Bigquery bigquery,
115114
final boolean batch) throws IOException {
116115

117116
JobConfigurationQuery queryConfig = new JobConfigurationQuery()
118-
.setQuery(querySql);
117+
.setQuery(querySql);
119118

120119
if (batch) {
121120
queryConfig.setPriority("BATCH");

bigquery/src/main/java/com/google/cloud/bigquery/samples/BigqueryUtils.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
15+
1516
package com.google.cloud.bigquery.samples;
1617

1718
import com.google.api.client.json.GenericJson;
@@ -44,7 +45,6 @@ public class BigqueryUtils {
4445
* static helper methods.
4546
*/
4647
protected BigqueryUtils() {
47-
4848
}
4949

5050
/**
@@ -53,12 +53,11 @@ protected BigqueryUtils() {
5353
* @param out Output stream we want to print to
5454
*/
5555
// [START print_rows]
56-
public static void printRows(final List<TableRow> rows, final PrintStream
57-
out) {
56+
public static void printRows(final List<TableRow> rows, final PrintStream out) {
5857
for (TableRow row : rows) {
5958
for (TableCell field : row.getF()) {
6059
out.printf("%-50s", field.getV());
61-
}
60+
}
6261
out.println();
6362
}
6463
}
@@ -73,14 +72,13 @@ public static void printRows(final List<TableRow> rows, final PrintStream
7372
* @throws InterruptedException InterruptedException
7473
*/
7574
// [START poll_job]
76-
public static Job pollJob(final Bigquery.Jobs.Get request, final long
77-
interval)
75+
public static Job pollJob(final Bigquery.Jobs.Get request, final long interval)
7876
throws IOException, InterruptedException {
7977
Job job = request.execute();
8078
while (!job.getStatus().getState().equals("DONE")) {
8179
System.out.println("Job is "
82-
+ job.getStatus().getState()
83-
+ " waiting " + interval + " milliseconds...");
80+
+ job.getStatus().getState()
81+
+ " waiting " + interval + " milliseconds...");
8482
Thread.sleep(interval);
8583
job = request.execute();
8684
}
@@ -97,7 +95,7 @@ public static Job pollJob(final Bigquery.Jobs.Get request, final long
9795
*/
9896
// [START paging]
9997
public static <T extends GenericJson> Iterator<T> getPages(
100-
final BigqueryRequest<T> requestTemplate) {
98+
final BigqueryRequest<T> requestTemplate) {
10199

102100
/**
103101
* An iterator class that pages through a Bigquery request.
@@ -168,8 +166,8 @@ public static TableSchema loadSchema(final Reader schemaSource) {
168166
TableSchema sourceSchema = new TableSchema();
169167

170168
List<TableFieldSchema> fields = (new Gson())
171-
.<List<TableFieldSchema>>fromJson(schemaSource,
172-
(new ArrayList<TableFieldSchema>()).getClass());
169+
.<List<TableFieldSchema>>fromJson(schemaSource,
170+
(new ArrayList<TableFieldSchema>()).getClass());
173171

174172
sourceSchema.setFields(fields);
175173

@@ -186,8 +184,7 @@ public static TableSchema loadSchema(final Reader schemaSource) {
186184
* @throws IOException Thrown if there is a network error connecting to
187185
* Bigquery.
188186
*/
189-
public static void listDatasets(final Bigquery bigquery, final String
190-
projectId)
187+
public static void listDatasets(final Bigquery bigquery, final String projectId)
191188
throws IOException {
192189
Datasets.List datasetRequest = bigquery.datasets().list(projectId);
193190
DatasetList datasetList = datasetRequest.execute();
@@ -201,5 +198,4 @@ public static void listDatasets(final Bigquery bigquery, final String
201198
}
202199
}
203200
// [END list_datasets]
204-
205201
}

bigquery/src/main/java/com/google/cloud/bigquery/samples/ExportDataCloudStorageSample.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
* Sample of how to Export Cloud Data.
2828
*/
2929
public class ExportDataCloudStorageSample {
30-
31-
/**
32-
* Protected constructor since this is a collection of static functions.
33-
*/
34-
protected ExportDataCloudStorageSample() {
35-
super();
36-
}
30+
/**
31+
* Protected constructor since this is a collection of static functions.
32+
*/
33+
protected ExportDataCloudStorageSample() {
34+
super();
35+
}
3736

3837
/**
3938
* This program can be run to demonstrate running a Bigquery query from the
@@ -43,8 +42,8 @@ protected ExportDataCloudStorageSample() {
4342
* @throws InterruptedException Should never be thrown.
4443
*/
4544
// [START main]
46-
public static void main(final String[] args) throws IOException,
47-
InterruptedException {
45+
public static void main(final String[] args)
46+
throws IOException, InterruptedException {
4847
Scanner scanner = new Scanner(System.in);
4948
System.out.println("Enter your project id: ");
5049
String projectId = scanner.nextLine();
@@ -53,15 +52,14 @@ public static void main(final String[] args) throws IOException,
5352
System.out.println("Enter your table id: ");
5453
String tableId = scanner.nextLine();
5554
System.out.println("Enter the Google Cloud Storage Path to which you'd "
56-
+ "like to export: ");
55+
+ "like to export: ");
5756
String cloudStoragePath = scanner.nextLine();
5857
System.out.println("Enter how often to check if your job is complete "
59-
+ "(milliseconds): ");
58+
+ "(milliseconds): ");
6059
long interval = scanner.nextLong();
6160
scanner.close();
6261

6362
run(cloudStoragePath, projectId, datasetId, tableId, interval);
64-
6563
}
6664
// [END main]
6765

@@ -120,16 +118,12 @@ public static Job extractJob(
120118
final TableReference table) throws IOException {
121119

122120
JobConfigurationExtract extract = new JobConfigurationExtract()
123-
.setSourceTable(table)
124-
.setDestinationUri(cloudStoragePath);
121+
.setSourceTable(table)
122+
.setDestinationUri(cloudStoragePath);
125123

126124
return bigquery.jobs().insert(table.getProjectId(),
127125
new Job().setConfiguration(new JobConfiguration().setExtract(extract)))
128126
.execute();
129127
}
130128
// [END extract_job]
131-
132-
133-
134-
135129
}

bigquery/src/main/java/com/google/cloud/bigquery/samples/GettingStarted.java

+3-26
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,24 @@
1111
* or implied. See the License for the specific language governing permissions and limitations under
1212
* the License.
1313
*/
14-
// [START all]
15-
package com.google.cloud.bigquery.samples;
16-
1714

15+
package com.google.cloud.bigquery.samples;
1816

19-
import com.google.api.client.auth.oauth2.Credential;
20-
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
21-
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
22-
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
23-
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl;
24-
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
17+
// [START all]
2518
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
26-
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
2719
import com.google.api.client.http.HttpTransport;
2820
import com.google.api.client.http.javanet.NetHttpTransport;
2921
import com.google.api.client.json.JsonFactory;
3022
import com.google.api.client.json.jackson2.JacksonFactory;
31-
import com.google.api.client.util.store.DataStoreFactory;
32-
import com.google.api.client.util.store.FileDataStoreFactory;
33-
import com.google.api.services.bigquery.Bigquery.Datasets;
34-
import com.google.api.services.bigquery.Bigquery.Jobs.Insert;
3523
import com.google.api.services.bigquery.Bigquery;
3624
import com.google.api.services.bigquery.BigqueryScopes;
37-
import com.google.api.services.bigquery.model.DatasetList;
3825
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
39-
import com.google.api.services.bigquery.model.Job;
40-
import com.google.api.services.bigquery.model.JobConfiguration;
41-
import com.google.api.services.bigquery.model.JobConfigurationQuery;
42-
import com.google.api.services.bigquery.model.JobReference;
4326
import com.google.api.services.bigquery.model.QueryRequest;
4427
import com.google.api.services.bigquery.model.QueryResponse;
4528
import com.google.api.services.bigquery.model.TableCell;
4629
import com.google.api.services.bigquery.model.TableRow;
4730

48-
import java.io.BufferedReader;
49-
import java.io.FileInputStream;
5031
import java.io.IOException;
51-
import java.io.InputStream;
52-
import java.io.InputStreamReader;
53-
import java.io.Reader;
54-
import java.util.Arrays;
5532
import java.util.List;
5633
import java.util.Scanner;
5734

@@ -144,7 +121,7 @@ private static void printResults(List<TableRow> rows) {
144121
*/
145122
public static void main(String[] args) throws IOException {
146123
Scanner sc;
147-
if(args.length == 0) {
124+
if (args.length == 0) {
148125
// Prompt the user to enter the id of the project to run the queries under
149126
System.out.print("Enter the project ID: ");
150127
sc = new Scanner(System.in);

0 commit comments

Comments
 (0)