Skip to content

Commit 1206737

Browse files
committed
runs google-java-format
1 parent 0ee7caf commit 1206737

9 files changed

Lines changed: 203 additions & 171 deletions

File tree

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.google.cloud.bigquery.LegacySQLTypeName;
5151
import com.google.cloud.bigquery.LoadJobConfiguration;
5252
import com.google.cloud.bigquery.QueryJobConfiguration;
53-
import com.google.cloud.bigquery.QueryParameterValue;
5453
import com.google.cloud.bigquery.Schema;
5554
import com.google.cloud.bigquery.StandardTableDefinition;
5655
import com.google.cloud.bigquery.Table;
@@ -238,7 +237,7 @@ public Boolean deleteTableFromId(String projectId, String datasetName, String ta
238237
return deleted;
239238
}
240239

241-
/**
240+
/**
242241
* Example of listing the tables in a dataset, specifying the page size.
243242
*/
244243
// [TARGET listTables(String, TableListOption...)]
@@ -253,7 +252,6 @@ public Page<Table> listTables(String datasetName) {
253252
return tables;
254253
}
255254

256-
257255
/**
258256
* Example of listing the tables in a dataset.
259257
*/
@@ -337,9 +335,7 @@ public long writeToTable(String datasetName, String tableName, String csvData)
337335
// [START ]
338336
TableId tableId = TableId.of(datasetName, tableName);
339337
WriteChannelConfiguration writeChannelConfiguration =
340-
WriteChannelConfiguration.newBuilder(tableId)
341-
.setFormatOptions(FormatOptions.csv())
342-
.build();
338+
WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
343339
TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
344340
// Write data to writer
345341
try {
@@ -400,9 +396,7 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath,
400396
// [START bigquery_load_from_file]
401397
TableId tableId = TableId.of(datasetName, tableName);
402398
WriteChannelConfiguration writeChannelConfiguration =
403-
WriteChannelConfiguration.newBuilder(tableId)
404-
.setFormatOptions(FormatOptions.csv())
405-
.build();
399+
WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
406400
// The location must be specified; other fields can be auto-detected.
407401
JobId jobId = JobId.newBuilder().setLocation(location).build();
408402
TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
@@ -430,17 +424,19 @@ public Long writeRemoteFileToTable(String datasetName, String tableName)
430424
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json";
431425
TableId tableId = TableId.of(datasetName, tableName);
432426
// Table field definition
433-
Field[] fields = new Field[] {
434-
Field.of("name", LegacySQLTypeName.STRING),
435-
Field.of("post_abbr", LegacySQLTypeName.STRING)
436-
};
427+
Field[] fields =
428+
new Field[] {
429+
Field.of("name", LegacySQLTypeName.STRING),
430+
Field.of("post_abbr", LegacySQLTypeName.STRING)
431+
};
437432
// Table schema definition
438433
Schema schema = Schema.of(fields);
439-
LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri)
440-
.setFormatOptions(FormatOptions.json())
441-
.setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
442-
.setSchema(schema)
443-
.build();
434+
LoadJobConfiguration configuration =
435+
LoadJobConfiguration.builder(tableId, sourceUri)
436+
.setFormatOptions(FormatOptions.json())
437+
.setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
438+
.setSchema(schema)
439+
.build();
444440
// Load the table
445441
Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
446442
remoteLoadJob = remoteLoadJob.waitFor();
@@ -468,10 +464,12 @@ public InsertAllResponse insertAll(String datasetName, String tableName) {
468464
Map<String, Object> recordsContent = new HashMap<>();
469465
recordsContent.put("stringField", "Hello, World!");
470466
rowContent.put("recordField", recordsContent);
471-
InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId)
472-
.addRow("rowId", rowContent)
473-
// More rows can be added in the same RPC by invoking .addRow() on the builder
474-
.build());
467+
InsertAllResponse response =
468+
bigquery.insertAll(
469+
InsertAllRequest.newBuilder(tableId)
470+
.addRow("rowId", rowContent)
471+
// More rows can be added in the same RPC by invoking .addRow() on the builder
472+
.build());
475473
if (response.hasErrors()) {
476474
// If any of the insertions failed, this lets you inspect the errors
477475
for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
@@ -553,8 +551,7 @@ public TableResult listTableDataFromId(String datasetName, String tableName) {
553551
public TableResult listTableDataSchema(
554552
String datasetName, String tableName, Schema schema, String field) {
555553
// [START ]
556-
TableResult tableData =
557-
bigquery.listTableData(datasetName, tableName, schema);
554+
TableResult tableData = bigquery.listTableData(datasetName, tableName, schema);
558555
for (FieldValueList row : tableData.iterateAll()) {
559556
row.get(field);
560557
}
@@ -647,7 +644,6 @@ public Job getJobFromId(String jobName) {
647644
return job;
648645
}
649646

650-
651647
/**
652648
* Example of cancelling a job.
653649
*/
@@ -690,10 +686,8 @@ public boolean cancelJobFromId(String jobName) {
690686
public void runQuery() throws InterruptedException {
691687
// [START bigquery_query]
692688
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
693-
String query =
694-
"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
695-
QueryJobConfiguration queryConfig =
696-
QueryJobConfiguration.newBuilder(query).build();
689+
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
690+
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
697691

698692
// Print the results.
699693
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/CloudSnippets.java

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import com.google.cloud.bigquery.BigQuery;
2020
import com.google.cloud.bigquery.FieldValue;
2121
import com.google.cloud.bigquery.FieldValueList;
22-
import com.google.cloud.bigquery.TableId;
2322
import com.google.cloud.bigquery.QueryJobConfiguration;
2423
import com.google.cloud.bigquery.QueryParameterValue;
24+
import com.google.cloud.bigquery.TableId;
25+
import java.util.concurrent.TimeoutException;
2526
import org.joda.time.DateTime;
2627
import org.joda.time.DateTimeZone;
2728
import org.joda.time.format.DateTimeFormatter;
2829
import org.joda.time.format.ISODateTimeFormat;
29-
import java.util.concurrent.TimeoutException;
3030

3131
/**
3232
* This class contains snippets for cloud.google.com documentation.
@@ -45,8 +45,7 @@ public CloudSnippets(BigQuery bigquery) {
4545
public void runLegacySqlQuery() throws InterruptedException {
4646
// [START bigquery_query_legacy]
4747
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
48-
String query =
49-
"SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus;";
48+
String query = "SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus;";
5049
QueryJobConfiguration queryConfig =
5150
// To use legacy SQL syntax, set useLegacySql to true.
5251
QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
@@ -67,8 +66,7 @@ public void runLegacySqlQuery() throws InterruptedException {
6766
public void runStandardSqlQuery() throws InterruptedException {
6867
// [START bigquery_query_standard]
6968
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
70-
String query =
71-
"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
69+
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
7270
QueryJobConfiguration queryConfig =
7371
// Note that setUseLegacySql is set to false by default
7472
QueryJobConfiguration.newBuilder(query).setUseLegacySql(false).build();
@@ -86,19 +84,19 @@ public void runStandardSqlQuery() throws InterruptedException {
8684
/**
8785
* Example of running a query and saving the results to a table.
8886
*/
89-
public void runQueryPermanentTable(String destinationDataset, String destinationTable) throws InterruptedException {
87+
public void runQueryPermanentTable(String destinationDataset, String destinationTable)
88+
throws InterruptedException {
9089
// [START bigquery_query_destination_table]
9190
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
9291
// String destinationDataset = 'my_destination_dataset';
9392
// String destinationTable = 'my_destination_table';
94-
String query =
95-
"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
93+
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
9694
QueryJobConfiguration queryConfig =
9795
// Note that setUseLegacySql is set to false by default
9896
QueryJobConfiguration.newBuilder(query)
99-
// Save the results of the query to a permanent table.
100-
.setDestinationTable(TableId.of(destinationDataset, destinationTable))
101-
.build();
97+
// Save the results of the query to a permanent table.
98+
.setDestinationTable(TableId.of(destinationDataset, destinationTable))
99+
.build();
102100

103101
// Print the results.
104102
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -113,22 +111,23 @@ public void runQueryPermanentTable(String destinationDataset, String destination
113111
/**
114112
* Example of running a query and saving the results to a table.
115113
*/
116-
public void runQueryLargeResults(String destinationDataset, String destinationTable) throws InterruptedException {
114+
public void runQueryLargeResults(String destinationDataset, String destinationTable)
115+
throws InterruptedException {
117116
// [START bigquery_query_legacy_large_results]
118117
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
119118
// String destinationDataset = 'my_destination_dataset';
120119
// String destinationTable = 'my_destination_table';
121-
String query =
122-
"SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus;";
120+
String query = "SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus;";
123121
QueryJobConfiguration queryConfig =
124122
// To use legacy SQL syntax, set useLegacySql to true.
125-
QueryJobConfiguration.newBuilder(query).setUseLegacySql(true)
126-
// Save the results of the query to a permanent table.
127-
.setDestinationTable(TableId.of(destinationDataset, destinationTable))
128-
// Allow results larger than the maximum response size.
129-
// If true, a destination table must be set.
130-
.setAllowLargeResults(true)
131-
.build();
123+
QueryJobConfiguration.newBuilder(query)
124+
.setUseLegacySql(true)
125+
// Save the results of the query to a permanent table.
126+
.setDestinationTable(TableId.of(destinationDataset, destinationTable))
127+
// Allow results larger than the maximum response size.
128+
// If true, a destination table must be set.
129+
.setAllowLargeResults(true)
130+
.build();
132131

133132
// Print the results.
134133
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -146,13 +145,12 @@ public void runQueryLargeResults(String destinationDataset, String destinationTa
146145
public void runUncachedQuery() throws TimeoutException, InterruptedException {
147146
// [START bigquery_query_no_cache]
148147
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
149-
String query =
150-
"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
148+
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
151149
QueryJobConfiguration queryConfig =
152150
QueryJobConfiguration.newBuilder(query)
153-
// Disable the query cache to force live query evaluation.
154-
.setUseQueryCache(false)
155-
.build();
151+
// Disable the query cache to force live query evaluation.
152+
.setUseQueryCache(false)
153+
.build();
156154

157155
// Print the results.
158156
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -170,15 +168,14 @@ public void runUncachedQuery() throws TimeoutException, InterruptedException {
170168
public void runBatchQuery() throws TimeoutException, InterruptedException {
171169
// [START bigquery_query_batch]
172170
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
173-
String query =
174-
"SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
171+
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
175172
QueryJobConfiguration queryConfig =
176173
QueryJobConfiguration.newBuilder(query)
177-
// Run at batch priority, which won't count toward concurrent rate
178-
// limit. See:
179-
// https://cloud.google.com/bigquery/docs/running-queries#batch
180-
.setPriority(QueryJobConfiguration.Priority.BATCH)
181-
.build();
174+
// Run at batch priority, which won't count toward concurrent rate
175+
// limit. See:
176+
// https://cloud.google.com/bigquery/docs/running-queries#batch
177+
.setPriority(QueryJobConfiguration.Priority.BATCH)
178+
.build();
182179

183180
// Print the results.
184181
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -207,9 +204,9 @@ public void runQueryWithNamedParameters() throws InterruptedException {
207204
// Note: Standard SQL is required to use query parameters.
208205
QueryJobConfiguration queryConfig =
209206
QueryJobConfiguration.newBuilder(query)
210-
.addNamedParameter("corpus", QueryParameterValue.string(corpus))
211-
.addNamedParameter("min_word_count", QueryParameterValue.int64(minWordCount))
212-
.build();
207+
.addNamedParameter("corpus", QueryParameterValue.string(corpus))
208+
.addNamedParameter("min_word_count", QueryParameterValue.int64(minWordCount))
209+
.build();
213210

214211
// Print the results.
215212
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -240,9 +237,9 @@ public void runQueryWithArrayParameters() throws InterruptedException {
240237
// Note: Standard SQL is required to use query parameters.
241238
QueryJobConfiguration queryConfig =
242239
QueryJobConfiguration.newBuilder(query)
243-
.addNamedParameter("gender", QueryParameterValue.string(gender))
244-
.addNamedParameter("states", QueryParameterValue.array(states, String.class))
245-
.build();
240+
.addNamedParameter("gender", QueryParameterValue.string(gender))
241+
.addNamedParameter("states", QueryParameterValue.array(states, String.class))
242+
.build();
246243

247244
// Print the results.
248245
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
@@ -265,12 +262,12 @@ public void runQueryWithTimestampParameters() throws InterruptedException {
265262
// Note: Standard SQL is required to use query parameters.
266263
QueryJobConfiguration queryConfig =
267264
QueryJobConfiguration.newBuilder(query)
268-
.addNamedParameter(
269-
"ts_value",
270-
QueryParameterValue.timestamp(
271-
// Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
272-
timestamp.getMillis() * 1000))
273-
.build();
265+
.addNamedParameter(
266+
"ts_value",
267+
QueryParameterValue.timestamp(
268+
// Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
269+
timestamp.getMillis() * 1000))
270+
.build();
274271

275272
// Print the results.
276273
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/DatasetSnippets.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* EDITING INSTRUCTIONS
1919
* This file is referenced in Dataset’s javadoc. Any change to this file should be reflected in
2020
* Dataset’s javadoc.
21-
*/
21+
*/
2222

2323
package com.google.cloud.examples.bigquery.snippets;
2424

@@ -32,7 +32,6 @@
3232
import com.google.cloud.bigquery.Table;
3333
import com.google.cloud.bigquery.TimePartitioning;
3434

35-
3635
/**
3736
* This class contains a number of snippets for the {@link Dataset} interface.
3837
*/
@@ -109,13 +108,13 @@ public boolean deleteDataset() {
109108
*/
110109
// [TARGET list(TableListOption...)]
111110
public Page<Table> list() {
112-
// [START ]
111+
// [START ]
113112
Page<Table> tables = dataset.list();
114113
for (Table table : tables.iterateAll()) {
115114
// do something with the table
116115
}
117116
// [END ]
118-
return tables;
117+
return tables;
119118
}
120119

121120
/**
@@ -139,10 +138,11 @@ public Table getTable(String tableName) {
139138
public Table createTable(String tableName, String fieldName) {
140139
// [START ]
141140
Schema schema = Schema.of(Field.of(fieldName, LegacySQLTypeName.STRING));
142-
StandardTableDefinition definition = StandardTableDefinition.newBuilder()
143-
.setSchema(schema)
144-
.setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY))
145-
.build();
141+
StandardTableDefinition definition =
142+
StandardTableDefinition.newBuilder()
143+
.setSchema(schema)
144+
.setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY))
145+
.build();
146146
Table table = dataset.create(tableName, definition);
147147
// [END ]
148148
return table;

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.cloud.bigquery.BigQueryException;
2929
import com.google.cloud.bigquery.Job;
3030
import com.google.cloud.bigquery.JobStatus;
31-
3231
import org.threeten.bp.Duration;
3332

3433
public class JobSnippets {

0 commit comments

Comments
 (0)