Skip to content

Commit 5597c01

Browse files
author
Jerjou Cheng
committed
Enforce style.
Also, relax some style things I disagree with.
1 parent 53b3a73 commit 5597c01

File tree

13 files changed

+226
-232
lines changed

13 files changed

+226
-232
lines changed

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-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
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

17+
// [START all]
1918
import com.google.api.client.auth.oauth2.Credential;
2019
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
2120
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
@@ -144,7 +143,7 @@ private static void printResults(List<TableRow> rows) {
144143
*/
145144
public static void main(String[] args) throws IOException {
146145
Scanner sc;
147-
if(args.length == 0) {
146+
if (args.length == 0) {
148147
// Prompt the user to enter the id of the project to run the queries under
149148
System.out.print("Enter the project ID: ");
150149
sc = new Scanner(System.in);

bigquery/src/main/java/com/google/cloud/bigquery/samples/LoadDataCSVSample.java renamed to bigquery/src/main/java/com/google/cloud/bigquery/samples/LoadDataCsvSample.java

+40-43
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.services.bigquery.Bigquery;
@@ -31,24 +32,23 @@
3132
/**
3233
* Cli tool to load data from a CSV into Bigquery.
3334
*/
34-
public class LoadDataCSVSample {
35-
36-
/**
37-
* Protected constructor since this is a collection of static methods.
38-
*/
39-
protected LoadDataCSVSample() {
35+
public class LoadDataCsvSample {
4036

41-
}
37+
/**
38+
* Protected constructor since this is a collection of static methods.
39+
*/
40+
protected LoadDataCsvSample() {
41+
}
4242

43-
/**
44-
* Cli tool to load data from a CSV into Bigquery.
45-
* @param args Command line args, should be empty
46-
* @throws IOException IOException
47-
* @throws InterruptedException InterruptedException
48-
*/
43+
/**
44+
* Cli tool to load data from a CSV into Bigquery.
45+
* @param args Command line args, should be empty
46+
* @throws IOException IOException
47+
* @throws InterruptedException InterruptedException
48+
*/
4949
// [START main]
50-
public static void main(final String[] args) throws IOException,
51-
InterruptedException {
50+
public static void main(final String[] args)
51+
throws IOException, InterruptedException {
5252
Scanner scanner = new Scanner(System.in);
5353
System.out.println("Enter your project id: ");
5454
String projectId = scanner.nextLine();
@@ -57,14 +57,14 @@ public static void main(final String[] args) throws IOException,
5757
System.out.println("Enter your table id: ");
5858
String tableId = scanner.nextLine();
5959
System.out.println("Enter the Google Cloud Storage Path to the data "
60-
+ "you'd like to load: ");
60+
+ "you'd like to load: ");
6161
String cloudStoragePath = scanner.nextLine();
6262
System.out.println("Enter the filepath to your schema: ");
6363
String sourceSchemaPath = scanner.nextLine();
6464

6565

6666
System.out.println("Enter how often to check if your job is complete "
67-
+ "(milliseconds): ");
67+
+ "(milliseconds): ");
6868
long interval = scanner.nextLong();
6969
scanner.close();
7070

@@ -74,21 +74,20 @@ public static void main(final String[] args) throws IOException,
7474
tableId,
7575
new FileReader(new File(sourceSchemaPath)),
7676
interval);
77-
7877
}
7978
// [END main]
8079

81-
/**
82-
* Run the bigquery ClI.
83-
* @param cloudStoragePath The bucket we are using
84-
* @param projectId Project id
85-
* @param datasetId datasetid
86-
* @param tableId tableid
87-
* @param schemaSource Source of the schema
88-
* @param interval interval to wait between polling in milliseconds
89-
* @throws IOException Thrown if there is an error connecting to Bigquery.
90-
* @throws InterruptedException Should never be thrown
91-
*/
80+
/**
81+
* Run the bigquery ClI.
82+
* @param cloudStoragePath The bucket we are using
83+
* @param projectId Project id
84+
* @param datasetId datasetid
85+
* @param tableId tableid
86+
* @param schemaSource Source of the schema
87+
* @param interval interval to wait between polling in milliseconds
88+
* @throws IOException Thrown if there is an error connecting to Bigquery.
89+
* @throws InterruptedException Should never be thrown
90+
*/
9291
// [START run]
9392
public static void run(
9493
final String cloudStoragePath,
@@ -121,15 +120,15 @@ public static void run(
121120
}
122121
// [END run]
123122

124-
/**
125-
* A job that extracts data from a table.
126-
* @param bigquery Bigquery service to use
127-
* @param cloudStoragePath Cloud storage bucket we are inserting into
128-
* @param table Table to extract from
129-
* @param schema The schema of the table we are loading into
130-
* @return The job to extract data from the table
131-
* @throws IOException Thrown if error connceting to Bigtable
132-
*/
123+
/**
124+
* A job that extracts data from a table.
125+
* @param bigquery Bigquery service to use
126+
* @param cloudStoragePath Cloud storage bucket we are inserting into
127+
* @param table Table to extract from
128+
* @param schema The schema of the table we are loading into
129+
* @return The job to extract data from the table
130+
* @throws IOException Thrown if error connceting to Bigtable
131+
*/
133132
// [START load_job]
134133
public static Job loadJob(
135134
final Bigquery bigquery,
@@ -138,15 +137,13 @@ public static Job loadJob(
138137
final TableSchema schema) throws IOException {
139138

140139
JobConfigurationLoad load = new JobConfigurationLoad()
141-
.setDestinationTable(table)
142-
.setSchema(schema)
143-
.setSourceUris(Collections.singletonList(cloudStoragePath));
140+
.setDestinationTable(table)
141+
.setSchema(schema)
142+
.setSourceUris(Collections.singletonList(cloudStoragePath));
144143

145144
return bigquery.jobs().insert(table.getProjectId(),
146145
new Job().setConfiguration(new JobConfiguration().setLoad(load)))
147146
.execute();
148147
}
149148
// [END load_job]
150-
151-
152149
}

0 commit comments

Comments
 (0)