Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs, tests, and lint cleanup #636

Merged
merged 7 commits into from
Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public class InsertAllRequest implements Serializable {
* id used by BigQuery to detect duplicate insertion requests on a best-effort basis.
*
* <p>Example usage of creating a row to insert:
* <pre> {@code
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* RowToInsert row = new RowToInsert("rowId", rowContent);
* <pre> {@code
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* RowToInsert row = new RowToInsert("rowId", rowContent);
* }</pre>
*
* @see <a href ="https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency">
Expand Down Expand Up @@ -177,16 +177,16 @@ public Builder addRow(RowToInsert rowToInsert) {
* Adds a row to be inserted with associated id.
*
* <p>Example usage of adding a row with associated id:
* <pre> {@code
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* builder.addRow("rowId", rowContent);
* <pre> {@code
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* builder.addRow("rowId", rowContent);
* }</pre>
*/
public Builder addRow(String id, Map<String, Object> content) {
Expand All @@ -198,16 +198,16 @@ public Builder addRow(String id, Map<String, Object> content) {
* Adds a row to be inserted without an associated id.
*
* <p>Example usage of adding a row without an associated id:
* <pre> {@code
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* builder.addRow(rowContent);
* <pre> {@code
* InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId);
* List<Long> repeatedFieldValue = Arrays.asList(1L, 2L);
* Map<String, Object> recordContent = new HashMap<String, Object>();
* recordContent.put("subfieldName1", "value");
* recordContent.put("subfieldName2", repeatedFieldValue);
* Map<String, Object> rowContent = new HashMap<String, Object>();
* rowContent.put("fieldName1", true);
* rowContent.put("fieldName2", recordContent);
* builder.addRow(rowContent);
* }</pre>
*/
public Builder addRow(Map<String, Object> content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@
* {@link QueryResponse#jobCompleted()} returns {@code true}.
*
* <p>Example usage of a query request:
* <pre> {@code
* // Substitute "field", "table" and "dataset" with real field, table and dataset identifiers
* QueryRequest request = QueryRequest.builder("SELECT field FROM table")
* .defaultDataset(DatasetId.of("dataset"))
* .maxWaitTime(60000L)
* .maxResults(1000L)
* .build();
* QueryResponse response = bigquery.query(request);
* while (!response.jobCompleted()) {
* Thread.sleep(1000);
* response = bigquery.getQueryResults(response.jobId());
* }
* List<BigQueryError> executionErrors = response.executionErrors();
* // look for errors in executionErrors
* QueryResult result = response.result();
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
* while(rowIterator.hasNext()) {
* List<FieldValue> row = rowIterator.next();
* // do something with row
* }
* <pre> {@code
* // Substitute "field", "table" and "dataset" with real field, table and dataset identifiers
* QueryRequest request = QueryRequest.builder("SELECT field FROM table")
* .defaultDataset(DatasetId.of("dataset"))
* .maxWaitTime(60000L)
* .maxResults(1000L)
* .build();
* QueryResponse response = bigquery.query(request);
* while (!response.jobCompleted()) {
* Thread.sleep(1000);
* response = bigquery.getQueryResults(response.jobId());
* }
* List<BigQueryError> executionErrors = response.executionErrors();
* // look for errors in executionErrors
* QueryResult result = response.result();
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
* while(rowIterator.hasNext()) {
* List<FieldValue> row = rowIterator.next();
* // do something with row
* }
* }</pre>
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/query">Query</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
* Query Request ({@link BigQuery#query(QueryRequest)}).
*
* <p>Example usage of a query response:
* <pre> {@code
* QueryResponse response = bigquery.query(request);
* while (!response.jobCompleted()) {
* Thread.sleep(1000);
* response = bigquery.getQueryResults(response.jobId());
* }
* List<BigQueryError> executionErrors = response.executionErrors();
* // look for errors in executionErrors
* QueryResult result = response.result();
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
* while(rowIterator.hasNext()) {
* List<FieldValue> row = rowIterator.next();
* // do something with row
* }
* <pre> {@code
* QueryResponse response = bigquery.query(request);
* while (!response.jobCompleted()) {
* Thread.sleep(1000);
* response = bigquery.getQueryResults(response.jobId());
* }
* List<BigQueryError> executionErrors = response.executionErrors();
* // look for errors in executionErrors
* QueryResult result = response.result();
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
* while(rowIterator.hasNext()) {
* List<FieldValue> row = rowIterator.next();
* // do something with row
* }
* }</pre>
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults">Get Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
* limitations under the License.
*/

package com.google.gcloud.bigquery;

import static com.google.gcloud.bigquery.BigQuery.DatasetField;
import static com.google.gcloud.bigquery.BigQuery.JobField;
import static com.google.gcloud.bigquery.BigQuery.JobListOption;
import static com.google.gcloud.bigquery.BigQuery.JobOption;
import static com.google.gcloud.bigquery.BigQuery.TableField;
import static com.google.gcloud.bigquery.BigQuery.TableOption;
package com.google.gcloud.bigquery.it;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -32,7 +26,42 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gcloud.Page;
import com.google.gcloud.WriteChannel;
import com.google.gcloud.bigquery.BigQuery;
import com.google.gcloud.bigquery.BigQuery.DatasetField;
import com.google.gcloud.bigquery.BigQuery.DatasetOption;
import com.google.gcloud.bigquery.BigQuery.JobField;
import com.google.gcloud.bigquery.BigQuery.JobListOption;
import com.google.gcloud.bigquery.BigQuery.JobOption;
import com.google.gcloud.bigquery.BigQuery.TableField;
import com.google.gcloud.bigquery.BigQuery.TableOption;
import com.google.gcloud.bigquery.BigQueryError;
import com.google.gcloud.bigquery.BigQueryException;
import com.google.gcloud.bigquery.CopyJobConfiguration;
import com.google.gcloud.bigquery.Dataset;
import com.google.gcloud.bigquery.DatasetId;
import com.google.gcloud.bigquery.DatasetInfo;
import com.google.gcloud.bigquery.ExternalTableDefinition;
import com.google.gcloud.bigquery.ExtractJobConfiguration;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.FieldValue;
import com.google.gcloud.bigquery.FormatOptions;
import com.google.gcloud.bigquery.InsertAllRequest;
import com.google.gcloud.bigquery.InsertAllResponse;
import com.google.gcloud.bigquery.Job;
import com.google.gcloud.bigquery.JobInfo;
import com.google.gcloud.bigquery.LoadJobConfiguration;
import com.google.gcloud.bigquery.QueryJobConfiguration;
import com.google.gcloud.bigquery.QueryRequest;
import com.google.gcloud.bigquery.QueryResponse;
import com.google.gcloud.bigquery.Schema;
import com.google.gcloud.bigquery.StandardTableDefinition;
import com.google.gcloud.bigquery.Table;
import com.google.gcloud.bigquery.TableDefinition;
import com.google.gcloud.bigquery.TableId;
import com.google.gcloud.bigquery.TableInfo;
import com.google.gcloud.bigquery.ViewDefinition;
import com.google.gcloud.bigquery.WriteChannelConfiguration;
import com.google.gcloud.bigquery.testing.RemoteBigQueryHelper;
import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.storage.BucketInfo;
Expand All @@ -45,7 +74,6 @@
import org.junit.Test;
import org.junit.rules.Timeout;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -140,7 +168,7 @@ public class ITBigQueryTest {
public Timeout globalTimeout = Timeout.seconds(300);

@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
public static void beforeClass() throws InterruptedException {
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
bigquery = bigqueryHelper.options().service();
Expand Down Expand Up @@ -169,8 +197,9 @@ public static void afterClass() throws ExecutionException, InterruptedException
if (bigquery != null) {
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
}
if (storage != null && !RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS)) {
if (LOG.isLoggable(Level.WARNING)) {
if (storage != null) {
boolean wasDeleted = RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS);
if (!wasDeleted && LOG.isLoggable(Level.WARNING)) {
LOG.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
}
}
Expand Down Expand Up @@ -685,7 +714,7 @@ public void testListJobsWithSelectedFields() {
}

@Test
public void testCreateAndGetJob() throws InterruptedException {
public void testCreateAndGetJob() {
String sourceTableName = "test_create_and_get_job_source_table";
String destinationTableName = "test_create_and_get_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
Expand Down Expand Up @@ -717,7 +746,7 @@ public void testCreateAndGetJob() throws InterruptedException {
}

@Test
public void testCreateAndGetJobWithSelectedFields() throws InterruptedException {
public void testCreateAndGetJobWithSelectedFields() {
String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table";
String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
Expand Down Expand Up @@ -874,20 +903,20 @@ public void testCancelJob() throws InterruptedException {
}

@Test
public void testCancelNonExistingJob() throws InterruptedException {
public void testCancelNonExistingJob() {
assertFalse(bigquery.cancel("test_cancel_non_existing_job"));
}

@Test
public void testInsertFromFile() throws InterruptedException, FileNotFoundException {
public void testInsertFromFile() throws InterruptedException {
String destinationTableName = "test_insert_from_file_table";
TableId tableId = TableId.of(DATASET, destinationTableName);
WriteChannelConfiguration configuration = WriteChannelConfiguration.builder(tableId)
.formatOptions(FormatOptions.json())
.createDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED)
.schema(TABLE_SCHEMA)
.build();
try (TableDataWriteChannel channel = bigquery.writer(configuration)) {
try (WriteChannel channel = bigquery.writer(configuration)) {
channel.write(ByteBuffer.wrap(JSON_CONTENT.getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) {
fail("IOException was not expected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
*
* <p>
* A typical capture usage:
* <pre> {@code
* <pre> {@code
* X restorableObj; // X instanceof Restorable<X>
* RestorableState<X> state = restorableObj.capture();
* .. persist state
* }</pre>
*
* A typical restore usage:
* <pre> {@code
* <pre> {@code
* RestorableState<X> state = ... // read from persistence
* X restorableObj = state.restore();
* ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
* to the Datastore upon {@link #submit}.
* A usage example:
* <pre> {@code
* Entity entity1 = datastore.get(key1);
* Batch batch = datastore.newBatch();
* Entity entity2 = Entity.builder(key2).set("name", "John").build();
* entity1 = Entity.builder(entity1).clear().setNull("bla").build();
* Entity entity3 = Entity.builder(key3).set("title", "title").build();
* batch.update(entity1);
* batch.add(entity2, entity3);
* batch.submit();
* Entity entity1 = datastore.get(key1);
* Batch batch = datastore.newBatch();
* Entity entity2 = Entity.builder(key2).set("name", "John").build();
* entity1 = Entity.builder(entity1).clear().setNull("bla").build();
* Entity entity3 = Entity.builder(key3).set("title", "title").build();
* batch.update(entity1);
* batch.add(entity2, entity3);
* batch.submit();
* } </pre>
*/
public interface Batch extends DatastoreBatchWriter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@
* <h3>A usage example:</h3>
*
* <p>When the type of the results is known the preferred usage would be:
* <pre>{@code
* Query<Entity> query =
* Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
* QueryResults<Entity> results = datastore.run(query);
* while (results.hasNext()) {
* Entity entity = results.next();
* ...
* }
* <pre> {@code
* Query<Entity> query =
* Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
* QueryResults<Entity> results = datastore.run(query);
* while (results.hasNext()) {
* Entity entity = results.next();
* ...
* }
* } </pre>
*
* <p>When the type of the results is unknown you can use this approach:
* <pre>{@code
* Query<?> query = Query.gqlQueryBuilder("select __key__ from kind").build();
* QueryResults<?> results = datastore.run(query);
* if (Key.class.isAssignableFrom(results.resultClass())) {
* QueryResults<Key> keys = (QueryResults<Key>) results;
* while (keys.hasNext()) {
* Key key = keys.next();
* ...
* }
* <pre> {@code
* Query<?> query = Query.gqlQueryBuilder("select __key__ from kind").build();
* QueryResults<?> results = datastore.run(query);
* if (Key.class.isAssignableFrom(results.resultClass())) {
* QueryResults<Key> keys = (QueryResults<Key>) results;
* while (keys.hasNext()) {
* Key key = keys.next();
* ...
* }
* }
* } </pre>
*
* @param <V> the type of the result values this query will produce
Expand Down
Loading