Skip to content

Commit 83c95ea

Browse files
committed
---
yaml --- r: 2109 b: refs/heads/pubsub-alpha c: 42727c0 h: refs/heads/master i: 2107: db6cc2e
1 parent 311ae41 commit 83c95ea

14 files changed

Lines changed: 324 additions & 159 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: edfb4707e6ae51b8bc15f4afb9dc1d44708dd08b
6+
refs/heads/pubsub-alpha: 42727c0b0097e08eb5f046f34c4733b5602c842f
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/README.md

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1212

1313
This client supports the following Google Cloud Platform services:
1414

15+
- [Google Cloud BigQuery] (#google-cloud-bigquery)
1516
- [Google Cloud Datastore] (#google-cloud-datastore)
16-
- [Google Cloud Storage] (#google-cloud-storage)
1717
- [Google Cloud Resource Manager] (#google-cloud-resource-manager)
18-
- [Google Cloud BigQuery] (#google-cloud-bigquery)
18+
- [Google Cloud Storage] (#google-cloud-storage)
1919

2020
> Note: This client is a work-in-progress, and may occasionally
2121
> make backwards-incompatible changes.
@@ -42,14 +42,14 @@ libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.1"
4242
Example Applications
4343
--------------------
4444

45+
- [`BigQueryExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality
46+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/BigQueryExample.html).
4547
- [`DatastoreExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java) - A simple command line interface for the Cloud Datastore
4648
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/DatastoreExample.html).
47-
- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
48-
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).
4949
- [`ResourceManagerExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java) - A simple command line interface providing some of Cloud Resource Manager's functionality
5050
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/ResourceManagerExample.html).
51-
- [`BigQueryExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality
52-
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/BigQueryExample.html).
51+
- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
52+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).
5353

5454
Specifying a Project ID
5555
-----------------------
@@ -109,6 +109,51 @@ Next, choose a method for authenticating API requests from within your project:
109109
4. Google Cloud SDK credentials
110110
5. Compute Engine credentials
111111
112+
Google Cloud BigQuery
113+
----------------------
114+
115+
- [API Documentation][bigquery-api]
116+
- [Official Documentation][cloud-bigquery-docs]
117+
118+
#### Preview
119+
120+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
121+
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
122+
123+
```java
124+
import com.google.gcloud.bigquery.BaseTableInfo;
125+
import com.google.gcloud.bigquery.BigQuery;
126+
import com.google.gcloud.bigquery.BigQueryOptions;
127+
import com.google.gcloud.bigquery.Field;
128+
import com.google.gcloud.bigquery.JobStatus;
129+
import com.google.gcloud.bigquery.LoadJobInfo;
130+
import com.google.gcloud.bigquery.Schema;
131+
import com.google.gcloud.bigquery.TableId;
132+
import com.google.gcloud.bigquery.TableInfo;
133+
134+
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
135+
TableId tableId = TableId.of("dataset", "table");
136+
BaseTableInfo info = bigquery.getTable(tableId);
137+
if (info == null) {
138+
System.out.println("Creating table " + tableId);
139+
Field integerField = Field.of("fieldName", Field.Type.integer());
140+
bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
141+
} else {
142+
System.out.println("Loading data into table " + tableId);
143+
LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path");
144+
loadJob = bigquery.create(loadJob);
145+
while (loadJob.status().state() != JobStatus.State.DONE) {
146+
Thread.sleep(1000L);
147+
loadJob = bigquery.getJob(loadJob.jobId());
148+
}
149+
if (loadJob.status().error() != null) {
150+
System.out.println("Job completed with errors");
151+
} else {
152+
System.out.println("Job succeeded");
153+
}
154+
}
155+
```
156+
112157
Google Cloud Datastore
113158
----------------------
114159
@@ -149,45 +194,6 @@ if (entity == null) {
149194
}
150195
```
151196
152-
Google Cloud Storage
153-
----------------------
154-
155-
- [API Documentation][storage-api]
156-
- [Official Documentation][cloud-storage-docs]
157-
158-
*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.*
159-
160-
#### Preview
161-
162-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
163-
164-
```java
165-
import static java.nio.charset.StandardCharsets.UTF_8;
166-
167-
import com.google.gcloud.storage.Blob;
168-
import com.google.gcloud.storage.BlobId;
169-
import com.google.gcloud.storage.Storage;
170-
import com.google.gcloud.storage.StorageOptions;
171-
172-
import java.nio.ByteBuffer;
173-
import java.nio.channels.WritableByteChannel;
174-
175-
Storage storage = StorageOptions.defaultInstance().service();
176-
BlobId blobId = BlobId.of("bucket", "blob_name");
177-
Blob blob = Blob.load(storage, blobId);
178-
if (blob == null) {
179-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
180-
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
181-
} else {
182-
System.out.println("Updating content for " + blobId.name());
183-
byte[] prevContent = blob.content();
184-
System.out.println(new String(prevContent, UTF_8));
185-
WritableByteChannel channel = blob.writer();
186-
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
187-
channel.close();
188-
}
189-
```
190-
191197
Google Cloud Resource Manager
192198
----------------------
193199
@@ -219,48 +225,42 @@ while (projectIterator.hasNext()) {
219225
}
220226
```
221227
222-
Google Cloud BigQuery
228+
Google Cloud Storage
223229
----------------------
224230
225-
- [API Documentation][bigquery-api]
226-
- [Official Documentation][cloud-bigquery-docs]
231+
- [API Documentation][storage-api]
232+
- [Official Documentation][cloud-storage-docs]
233+
234+
*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.*
227235
228236
#### Preview
229237
230-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
231-
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
238+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
232239
233240
```java
234-
import com.google.gcloud.bigquery.BaseTableInfo;
235-
import com.google.gcloud.bigquery.BigQuery;
236-
import com.google.gcloud.bigquery.BigQueryOptions;
237-
import com.google.gcloud.bigquery.Field;
238-
import com.google.gcloud.bigquery.JobStatus;
239-
import com.google.gcloud.bigquery.LoadJobInfo;
240-
import com.google.gcloud.bigquery.Schema;
241-
import com.google.gcloud.bigquery.TableId;
242-
import com.google.gcloud.bigquery.TableInfo;
241+
import static java.nio.charset.StandardCharsets.UTF_8;
243242
244-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
245-
TableId tableId = TableId.of("dataset", "table");
246-
BaseTableInfo info = bigquery.getTable(tableId);
247-
if (info == null) {
248-
System.out.println("Creating table " + tableId);
249-
Field integerField = Field.of("fieldName", Field.Type.integer());
250-
bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
243+
import com.google.gcloud.storage.Blob;
244+
import com.google.gcloud.storage.BlobId;
245+
import com.google.gcloud.storage.Storage;
246+
import com.google.gcloud.storage.StorageOptions;
247+
248+
import java.nio.ByteBuffer;
249+
import java.nio.channels.WritableByteChannel;
250+
251+
Storage storage = StorageOptions.defaultInstance().service();
252+
BlobId blobId = BlobId.of("bucket", "blob_name");
253+
Blob blob = Blob.load(storage, blobId);
254+
if (blob == null) {
255+
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
256+
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
251257
} else {
252-
System.out.println("Loading data into table " + tableId);
253-
LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path");
254-
loadJob = bigquery.create(loadJob);
255-
while (loadJob.status().state() != JobStatus.State.DONE) {
256-
Thread.sleep(1000L);
257-
loadJob = bigquery.getJob(loadJob.jobId());
258-
}
259-
if (loadJob.status().error() != null) {
260-
System.out.println("Job completed with errors");
261-
} else {
262-
System.out.println("Job succeeded");
263-
}
258+
System.out.println("Updating content for " + blobId.name());
259+
byte[] prevContent = blob.content();
260+
System.out.println(new String(prevContent, UTF_8));
261+
WritableByteChannel channel = blob.writer();
262+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
263+
channel.close();
264264
}
265265
```
266266

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public InsertAllResponse insertAll(InsertAllRequest request) throws BigQueryExce
412412
final TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest();
413413
requestPb.setIgnoreUnknownValues(request.ignoreUnknownValues());
414414
requestPb.setSkipInvalidRows(request.skipInvalidRows());
415+
requestPb.setTemplateSuffix(request.templateSuffix());
415416
List<Rows> rowsPb = Lists.transform(request.rows(), new Function<RowToInsert, Rows>() {
416417
@Override
417418
public Rows apply(RowToInsert rowToInsert) {

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.gcloud.bigquery;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import com.google.common.base.MoreObjects;
2022

2123
import java.io.Serializable;
@@ -85,7 +87,7 @@ public static FormatOptions datastoreBackup() {
8587
* Default options for the provided format.
8688
*/
8789
public static FormatOptions of(String format) {
88-
if (format.equals(CSV)) {
90+
if (checkNotNull(format).equals(CSV)) {
8991
return csv();
9092
}
9193
return new FormatOptions(format);

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/InsertAllRequest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class InsertAllRequest implements Serializable {
4545
private final List<RowToInsert> rows;
4646
private final Boolean skipInvalidRows;
4747
private final Boolean ignoreUnknownValues;
48+
private final String templateSuffix;
4849

4950
/**
5051
* A Google Big Query row to be inserted into a table. Each {@code RowToInsert} has an associated
@@ -140,6 +141,7 @@ public static final class Builder {
140141
private List<RowToInsert> rows;
141142
private Boolean skipInvalidRows;
142143
private Boolean ignoreUnknownValues;
144+
private String templateSuffix;
143145

144146
private Builder() {}
145147

@@ -231,6 +233,20 @@ public Builder ignoreUnknownValues(boolean ignoreUnknownValues) {
231233
return this;
232234
}
233235

236+
/**
237+
* If specified, the destination table is treated as a base template. Rows are inserted into an
238+
* instance table named "{destination}{templateSuffix}". BigQuery will manage the creation of
239+
* the instance table, using the schema of the base template table.
240+
*
241+
* @see <a
242+
* href="https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tables">
243+
* Template Tables</a>
244+
*/
245+
public Builder templateSuffix(String templateSuffix) {
246+
this.templateSuffix = templateSuffix;
247+
return this;
248+
}
249+
234250
public InsertAllRequest build() {
235251
return new InsertAllRequest(this);
236252
}
@@ -241,6 +257,7 @@ private InsertAllRequest(Builder builder) {
241257
this.rows = ImmutableList.copyOf(checkNotNull(builder.rows));
242258
this.ignoreUnknownValues = builder.ignoreUnknownValues;
243259
this.skipInvalidRows = builder.skipInvalidRows;
260+
this.templateSuffix = builder.templateSuffix;
244261
}
245262

246263
/**
@@ -273,6 +290,19 @@ public Boolean skipInvalidRows() {
273290
return skipInvalidRows;
274291
}
275292

293+
/**
294+
* If specified, the destination table is treated as a base template. Rows are inserted into an
295+
* instance table named "{destination}{templateSuffix}". BigQuery will manage the creation of the
296+
* instance table, using the schema of the base template table.
297+
*
298+
* @see <a
299+
* href="https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tables">
300+
* Template Tables</a>
301+
*/
302+
public String templateSuffix() {
303+
return templateSuffix;
304+
}
305+
276306
/**
277307
* Returns a builder for an {@code InsertAllRequest} object given the destination table.
278308
*/
@@ -384,12 +414,13 @@ public String toString() {
384414
.add("rows", rows)
385415
.add("ignoreUnknownValues", ignoreUnknownValues)
386416
.add("skipInvalidRows", skipInvalidRows)
417+
.add("templateSuffix", templateSuffix)
387418
.toString();
388419
}
389420

390421
@Override
391422
public int hashCode() {
392-
return Objects.hash(table, rows, ignoreUnknownValues, skipInvalidRows);
423+
return Objects.hash(table, rows, ignoreUnknownValues, skipInvalidRows, templateSuffix);
393424
}
394425

395426
@Override
@@ -401,6 +432,7 @@ public boolean equals(Object obj) {
401432
return Objects.equals(table, other.table)
402433
&& Objects.equals(rows, other.rows)
403434
&& Objects.equals(ignoreUnknownValues, other.ignoreUnknownValues)
404-
&& Objects.equals(skipInvalidRows, other.skipInvalidRows);
435+
&& Objects.equals(skipInvalidRows, other.skipInvalidRows)
436+
&& Objects.equals(templateSuffix, other.templateSuffix);
405437
}
406438
}

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ public void testInsertAll() {
614614
.rows(rows)
615615
.skipInvalidRows(false)
616616
.ignoreUnknownValues(true)
617+
.templateSuffix("suffix")
617618
.build();
618619
TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest().setRows(
619620
Lists.transform(rows, new Function<RowToInsert, TableDataInsertAllRequest.Rows>() {
@@ -623,7 +624,7 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
623624
.setJson(rowToInsert.content());
624625
}
625626
})
626-
).setSkipInvalidRows(false).setIgnoreUnknownValues(true);
627+
).setSkipInvalidRows(false).setIgnoreUnknownValues(true).setTemplateSuffix("suffix");
627628
TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse().setInsertErrors(
628629
ImmutableList.of(new TableDataInsertAllResponse.InsertErrors().setIndex(0L).setErrors(
629630
ImmutableList.of(new ErrorProto().setMessage("ErrorMessage")))));

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,41 @@ public void testInsertAll() {
475475
assertTrue(bigquery.delete(TableId.of(DATASET, tableName)));
476476
}
477477

478+
@Test
479+
public void testInsertAllWithSuffix() {
480+
String tableName = "test_insert_all_with_suffix_table";
481+
BaseTableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), TABLE_SCHEMA);
482+
assertNotNull(bigquery.create(tableInfo));
483+
InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId())
484+
.addRow(ImmutableMap.<String, Object>of(
485+
"TimestampField", "2014-08-19 07:41:35.220 -05:00",
486+
"StringField", "stringValue",
487+
"IntegerField", ImmutableList.of(0, 1),
488+
"BooleanField", false,
489+
"RecordField", ImmutableMap.of(
490+
"TimestampField", "1969-07-20 20:18:04 UTC",
491+
"IntegerField", ImmutableList.of(1, 0),
492+
"BooleanField", true)))
493+
.addRow(ImmutableMap.<String, Object>of(
494+
"TimestampField", "2014-08-19 07:41:35.220 -05:00",
495+
"StringField", "stringValue",
496+
"IntegerField", ImmutableList.of(0, 1),
497+
"BooleanField", false,
498+
"RecordField", ImmutableMap.of(
499+
"TimestampField", "1969-07-20 20:18:04 UTC",
500+
"IntegerField", ImmutableList.of(1, 0),
501+
"BooleanField", true)))
502+
.templateSuffix("_suffix")
503+
.build();
504+
InsertAllResponse response = bigquery.insertAll(request);
505+
assertFalse(response.hasErrors());
506+
assertEquals(0, response.insertErrors().size());
507+
String newTableName = tableName + "_suffix";
508+
assertNotNull(bigquery.getTable(DATASET, newTableName, TableOption.fields()));
509+
assertTrue(bigquery.delete(TableId.of(DATASET, tableName)));
510+
assertTrue(bigquery.delete(TableId.of(DATASET, newTableName)));
511+
}
512+
478513
@Test
479514
public void testInsertAllWithErrors() {
480515
String tableName = "test_insert_all_with_errors_table";

0 commit comments

Comments
 (0)