Skip to content

Commit 8fb9e91

Browse files
committed
Merge pull request #636 from ajkannan/minor-cleanup
Docs, tests, and lint cleanup
2 parents 1ab48bb + deb228f commit 8fb9e91

17 files changed

Lines changed: 224 additions & 171 deletions

File tree

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/InsertAllRequest.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public class InsertAllRequest implements Serializable {
5252
* id used by BigQuery to detect duplicate insertion requests on a best-effort basis.
5353
*
5454
* <p>Example usage of creating a row to insert:
55-
* <pre> {@code
56-
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
57-
* Map<String, Object> recordContent = new HashMap<String, Object>();
58-
* recordContent.put("subfieldName1", "value");
59-
* recordContent.put("subfieldName2", repeatedFieldValue);
60-
* Map<String, Object> rowContent = new HashMap<String, Object>();
61-
* rowContent.put("fieldName1", true);
62-
* rowContent.put("fieldName2", recordContent);
63-
* RowToInsert row = new RowToInsert("rowId", rowContent);
55+
* <pre> {@code
56+
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
57+
* Map<String, Object> recordContent = new HashMap<String, Object>();
58+
* recordContent.put("subfieldName1", "value");
59+
* recordContent.put("subfieldName2", repeatedFieldValue);
60+
* Map<String, Object> rowContent = new HashMap<String, Object>();
61+
* rowContent.put("fieldName1", true);
62+
* rowContent.put("fieldName2", recordContent);
63+
* RowToInsert row = new RowToInsert("rowId", rowContent);
6464
* }</pre>
6565
*
6666
* @see <a href ="https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency">
@@ -177,16 +177,16 @@ public Builder addRow(RowToInsert rowToInsert) {
177177
* Adds a row to be inserted with associated id.
178178
*
179179
* <p>Example usage of adding a row with associated id:
180-
* <pre> {@code
181-
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
182-
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
183-
* Map<String, Object> recordContent = new HashMap<String, Object>();
184-
* recordContent.put("subfieldName1", "value");
185-
* recordContent.put("subfieldName2", repeatedFieldValue);
186-
* Map<String, Object> rowContent = new HashMap<String, Object>();
187-
* rowContent.put("fieldName1", true);
188-
* rowContent.put("fieldName2", recordContent);
189-
* builder.addRow("rowId", rowContent);
180+
* <pre> {@code
181+
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
182+
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
183+
* Map<String, Object> recordContent = new HashMap<String, Object>();
184+
* recordContent.put("subfieldName1", "value");
185+
* recordContent.put("subfieldName2", repeatedFieldValue);
186+
* Map<String, Object> rowContent = new HashMap<String, Object>();
187+
* rowContent.put("fieldName1", true);
188+
* rowContent.put("fieldName2", recordContent);
189+
* builder.addRow("rowId", rowContent);
190190
* }</pre>
191191
*/
192192
public Builder addRow(String id, Map<String, Object> content) {
@@ -198,16 +198,16 @@ public Builder addRow(String id, Map<String, Object> content) {
198198
* Adds a row to be inserted without an associated id.
199199
*
200200
* <p>Example usage of adding a row without an associated id:
201-
* <pre> {@code
202-
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
203-
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
204-
* Map<String, Object> recordContent = new HashMap<String, Object>();
205-
* recordContent.put("subfieldName1", "value");
206-
* recordContent.put("subfieldName2", repeatedFieldValue);
207-
* Map<String, Object> rowContent = new HashMap<String, Object>();
208-
* rowContent.put("fieldName1", true);
209-
* rowContent.put("fieldName2", recordContent);
210-
* builder.addRow(rowContent);
201+
* <pre> {@code
202+
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
203+
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
204+
* Map<String, Object> recordContent = new HashMap<String, Object>();
205+
* recordContent.put("subfieldName1", "value");
206+
* recordContent.put("subfieldName2", repeatedFieldValue);
207+
* Map<String, Object> rowContent = new HashMap<String, Object>();
208+
* rowContent.put("fieldName1", true);
209+
* rowContent.put("fieldName2", recordContent);
210+
* builder.addRow(rowContent);
211211
* }</pre>
212212
*/
213213
public Builder addRow(Map<String, Object> content) {

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryRequest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@
3535
* {@link QueryResponse#jobCompleted()} returns {@code true}.
3636
*
3737
* <p>Example usage of a query request:
38-
* <pre> {@code
39-
* // Substitute "field", "table" and "dataset" with real field, table and dataset identifiers
40-
* QueryRequest request = QueryRequest.builder("SELECT field FROM table")
41-
* .defaultDataset(DatasetId.of("dataset"))
42-
* .maxWaitTime(60000L)
43-
* .maxResults(1000L)
44-
* .build();
45-
* QueryResponse response = bigquery.query(request);
46-
* while (!response.jobCompleted()) {
47-
* Thread.sleep(1000);
48-
* response = bigquery.getQueryResults(response.jobId());
49-
* }
50-
* List<BigQueryError> executionErrors = response.executionErrors();
51-
* // look for errors in executionErrors
52-
* QueryResult result = response.result();
53-
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
54-
* while(rowIterator.hasNext()) {
55-
* List<FieldValue> row = rowIterator.next();
56-
* // do something with row
57-
* }
38+
* <pre> {@code
39+
* // Substitute "field", "table" and "dataset" with real field, table and dataset identifiers
40+
* QueryRequest request = QueryRequest.builder("SELECT field FROM table")
41+
* .defaultDataset(DatasetId.of("dataset"))
42+
* .maxWaitTime(60000L)
43+
* .maxResults(1000L)
44+
* .build();
45+
* QueryResponse response = bigquery.query(request);
46+
* while (!response.jobCompleted()) {
47+
* Thread.sleep(1000);
48+
* response = bigquery.getQueryResults(response.jobId());
49+
* }
50+
* List<BigQueryError> executionErrors = response.executionErrors();
51+
* // look for errors in executionErrors
52+
* QueryResult result = response.result();
53+
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
54+
* while(rowIterator.hasNext()) {
55+
* List<FieldValue> row = rowIterator.next();
56+
* // do something with row
57+
* }
5858
* }</pre>
5959
*
6060
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/query">Query</a>

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryResponse.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@
2929
* Query Request ({@link BigQuery#query(QueryRequest)}).
3030
*
3131
* <p>Example usage of a query response:
32-
* <pre> {@code
33-
* QueryResponse response = bigquery.query(request);
34-
* while (!response.jobCompleted()) {
35-
* Thread.sleep(1000);
36-
* response = bigquery.getQueryResults(response.jobId());
37-
* }
38-
* List<BigQueryError> executionErrors = response.executionErrors();
39-
* // look for errors in executionErrors
40-
* QueryResult result = response.result();
41-
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
42-
* while(rowIterator.hasNext()) {
43-
* List<FieldValue> row = rowIterator.next();
44-
* // do something with row
45-
* }
32+
* <pre> {@code
33+
* QueryResponse response = bigquery.query(request);
34+
* while (!response.jobCompleted()) {
35+
* Thread.sleep(1000);
36+
* response = bigquery.getQueryResults(response.jobId());
37+
* }
38+
* List<BigQueryError> executionErrors = response.executionErrors();
39+
* // look for errors in executionErrors
40+
* QueryResult result = response.result();
41+
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
42+
* while(rowIterator.hasNext()) {
43+
* List<FieldValue> row = rowIterator.next();
44+
* // do something with row
45+
* }
4646
* }</pre>
4747
*
4848
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults">Get Query

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java renamed to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/it/ITBigQueryTest.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.bigquery;
18-
19-
import static com.google.gcloud.bigquery.BigQuery.DatasetField;
20-
import static com.google.gcloud.bigquery.BigQuery.JobField;
21-
import static com.google.gcloud.bigquery.BigQuery.JobListOption;
22-
import static com.google.gcloud.bigquery.BigQuery.JobOption;
23-
import static com.google.gcloud.bigquery.BigQuery.TableField;
24-
import static com.google.gcloud.bigquery.BigQuery.TableOption;
17+
package com.google.gcloud.bigquery.it;
18+
2519
import static org.junit.Assert.assertEquals;
2620
import static org.junit.Assert.assertFalse;
2721
import static org.junit.Assert.assertNotNull;
@@ -32,7 +26,42 @@
3226
import com.google.common.collect.ImmutableList;
3327
import com.google.common.collect.ImmutableMap;
3428
import com.google.gcloud.Page;
29+
import com.google.gcloud.WriteChannel;
30+
import com.google.gcloud.bigquery.BigQuery;
31+
import com.google.gcloud.bigquery.BigQuery.DatasetField;
3532
import com.google.gcloud.bigquery.BigQuery.DatasetOption;
33+
import com.google.gcloud.bigquery.BigQuery.JobField;
34+
import com.google.gcloud.bigquery.BigQuery.JobListOption;
35+
import com.google.gcloud.bigquery.BigQuery.JobOption;
36+
import com.google.gcloud.bigquery.BigQuery.TableField;
37+
import com.google.gcloud.bigquery.BigQuery.TableOption;
38+
import com.google.gcloud.bigquery.BigQueryError;
39+
import com.google.gcloud.bigquery.BigQueryException;
40+
import com.google.gcloud.bigquery.CopyJobConfiguration;
41+
import com.google.gcloud.bigquery.Dataset;
42+
import com.google.gcloud.bigquery.DatasetId;
43+
import com.google.gcloud.bigquery.DatasetInfo;
44+
import com.google.gcloud.bigquery.ExternalTableDefinition;
45+
import com.google.gcloud.bigquery.ExtractJobConfiguration;
46+
import com.google.gcloud.bigquery.Field;
47+
import com.google.gcloud.bigquery.FieldValue;
48+
import com.google.gcloud.bigquery.FormatOptions;
49+
import com.google.gcloud.bigquery.InsertAllRequest;
50+
import com.google.gcloud.bigquery.InsertAllResponse;
51+
import com.google.gcloud.bigquery.Job;
52+
import com.google.gcloud.bigquery.JobInfo;
53+
import com.google.gcloud.bigquery.LoadJobConfiguration;
54+
import com.google.gcloud.bigquery.QueryJobConfiguration;
55+
import com.google.gcloud.bigquery.QueryRequest;
56+
import com.google.gcloud.bigquery.QueryResponse;
57+
import com.google.gcloud.bigquery.Schema;
58+
import com.google.gcloud.bigquery.StandardTableDefinition;
59+
import com.google.gcloud.bigquery.Table;
60+
import com.google.gcloud.bigquery.TableDefinition;
61+
import com.google.gcloud.bigquery.TableId;
62+
import com.google.gcloud.bigquery.TableInfo;
63+
import com.google.gcloud.bigquery.ViewDefinition;
64+
import com.google.gcloud.bigquery.WriteChannelConfiguration;
3665
import com.google.gcloud.bigquery.testing.RemoteBigQueryHelper;
3766
import com.google.gcloud.storage.BlobInfo;
3867
import com.google.gcloud.storage.BucketInfo;
@@ -45,7 +74,6 @@
4574
import org.junit.Test;
4675
import org.junit.rules.Timeout;
4776

48-
import java.io.FileNotFoundException;
4977
import java.io.IOException;
5078
import java.nio.ByteBuffer;
5179
import java.nio.charset.StandardCharsets;
@@ -140,7 +168,7 @@ public class ITBigQueryTest {
140168
public Timeout globalTimeout = Timeout.seconds(300);
141169

142170
@BeforeClass
143-
public static void beforeClass() throws IOException, InterruptedException {
171+
public static void beforeClass() throws InterruptedException {
144172
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
145173
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
146174
bigquery = bigqueryHelper.options().service();
@@ -169,8 +197,9 @@ public static void afterClass() throws ExecutionException, InterruptedException
169197
if (bigquery != null) {
170198
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
171199
}
172-
if (storage != null && !RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS)) {
173-
if (LOG.isLoggable(Level.WARNING)) {
200+
if (storage != null) {
201+
boolean wasDeleted = RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS);
202+
if (!wasDeleted && LOG.isLoggable(Level.WARNING)) {
174203
LOG.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
175204
}
176205
}
@@ -685,7 +714,7 @@ public void testListJobsWithSelectedFields() {
685714
}
686715

687716
@Test
688-
public void testCreateAndGetJob() throws InterruptedException {
717+
public void testCreateAndGetJob() {
689718
String sourceTableName = "test_create_and_get_job_source_table";
690719
String destinationTableName = "test_create_and_get_job_destination_table";
691720
TableId sourceTable = TableId.of(DATASET, sourceTableName);
@@ -717,7 +746,7 @@ public void testCreateAndGetJob() throws InterruptedException {
717746
}
718747

719748
@Test
720-
public void testCreateAndGetJobWithSelectedFields() throws InterruptedException {
749+
public void testCreateAndGetJobWithSelectedFields() {
721750
String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table";
722751
String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table";
723752
TableId sourceTable = TableId.of(DATASET, sourceTableName);
@@ -874,20 +903,20 @@ public void testCancelJob() throws InterruptedException {
874903
}
875904

876905
@Test
877-
public void testCancelNonExistingJob() throws InterruptedException {
906+
public void testCancelNonExistingJob() {
878907
assertFalse(bigquery.cancel("test_cancel_non_existing_job"));
879908
}
880909

881910
@Test
882-
public void testInsertFromFile() throws InterruptedException, FileNotFoundException {
911+
public void testInsertFromFile() throws InterruptedException {
883912
String destinationTableName = "test_insert_from_file_table";
884913
TableId tableId = TableId.of(DATASET, destinationTableName);
885914
WriteChannelConfiguration configuration = WriteChannelConfiguration.builder(tableId)
886915
.formatOptions(FormatOptions.json())
887916
.createDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED)
888917
.schema(TABLE_SCHEMA)
889918
.build();
890-
try (TableDataWriteChannel channel = bigquery.writer(configuration)) {
919+
try (WriteChannel channel = bigquery.writer(configuration)) {
891920
channel.write(ByteBuffer.wrap(JSON_CONTENT.getBytes(StandardCharsets.UTF_8)));
892921
} catch (IOException e) {
893922
fail("IOException was not expected");

gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
*
2222
* <p>
2323
* A typical capture usage:
24-
* <pre> {@code
24+
* <pre> {@code
2525
* X restorableObj; // X instanceof Restorable<X>
2626
* RestorableState<X> state = restorableObj.capture();
2727
* .. persist state
2828
* }</pre>
2929
*
3030
* A typical restore usage:
31-
* <pre> {@code
31+
* <pre> {@code
3232
* RestorableState<X> state = ... // read from persistence
3333
* X restorableObj = state.restore();
3434
* ...

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Batch.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
* to the Datastore upon {@link #submit}.
2525
* A usage example:
2626
* <pre> {@code
27-
* Entity entity1 = datastore.get(key1);
28-
* Batch batch = datastore.newBatch();
29-
* Entity entity2 = Entity.builder(key2).set("name", "John").build();
30-
* entity1 = Entity.builder(entity1).clear().setNull("bla").build();
31-
* Entity entity3 = Entity.builder(key3).set("title", "title").build();
32-
* batch.update(entity1);
33-
* batch.add(entity2, entity3);
34-
* batch.submit();
27+
* Entity entity1 = datastore.get(key1);
28+
* Batch batch = datastore.newBatch();
29+
* Entity entity2 = Entity.builder(key2).set("name", "John").build();
30+
* entity1 = Entity.builder(entity1).clear().setNull("bla").build();
31+
* Entity entity3 = Entity.builder(key3).set("title", "title").build();
32+
* batch.update(entity1);
33+
* batch.add(entity2, entity3);
34+
* batch.submit();
3535
* } </pre>
3636
*/
3737
public interface Batch extends DatastoreBatchWriter {

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@
4343
* <h3>A usage example:</h3>
4444
*
4545
* <p>When the type of the results is known the preferred usage would be:
46-
* <pre>{@code
47-
* Query<Entity> query =
48-
* Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
49-
* QueryResults<Entity> results = datastore.run(query);
50-
* while (results.hasNext()) {
51-
* Entity entity = results.next();
52-
* ...
53-
* }
46+
* <pre> {@code
47+
* Query<Entity> query =
48+
* Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
49+
* QueryResults<Entity> results = datastore.run(query);
50+
* while (results.hasNext()) {
51+
* Entity entity = results.next();
52+
* ...
53+
* }
5454
* } </pre>
5555
*
5656
* <p>When the type of the results is unknown you can use this approach:
57-
* <pre>{@code
58-
* Query<?> query = Query.gqlQueryBuilder("select __key__ from kind").build();
59-
* QueryResults<?> results = datastore.run(query);
60-
* if (Key.class.isAssignableFrom(results.resultClass())) {
61-
* QueryResults<Key> keys = (QueryResults<Key>) results;
62-
* while (keys.hasNext()) {
63-
* Key key = keys.next();
64-
* ...
65-
* }
57+
* <pre> {@code
58+
* Query<?> query = Query.gqlQueryBuilder("select __key__ from kind").build();
59+
* QueryResults<?> results = datastore.run(query);
60+
* if (Key.class.isAssignableFrom(results.resultClass())) {
61+
* QueryResults<Key> keys = (QueryResults<Key>) results;
62+
* while (keys.hasNext()) {
63+
* Key key = keys.next();
64+
* ...
6665
* }
66+
* }
6767
* } </pre>
6868
*
6969
* @param <V> the type of the result values this query will produce

0 commit comments

Comments
 (0)