Skip to content

Commit db6cc2e

Browse files
committed
---
yaml --- r: 2107 b: refs/heads/pubsub-alpha c: 823f0de h: refs/heads/master i: 2105: 63b2673 2103: c26a9e8
1 parent cf2e216 commit db6cc2e

10 files changed

Lines changed: 137 additions & 23 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: 6af6db4cdfbc1adf69f5eb8e668fdf5f8b089766
6+
refs/heads/pubsub-alpha: 823f0de985d9217d9c3fe81af7e6054d9d6da18c
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

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/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/main/java/com/google/gcloud/bigquery/package-info.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,28 @@
1818
* A client to Google Cloud BigQuery.
1919
*
2020
* <p>A simple usage example:
21-
* <pre>{@code
22-
* //TODO(mziccard): add code example
23-
* }</pre>
21+
* <pre> {@code
22+
* BigQuery bigquery = BigQueryOptions.defaultInstance().service();
23+
* TableId tableId = TableId.of("dataset", "table");
24+
* BaseTableInfo info = bigquery.getTable(tableId);
25+
* if (info == null) {
26+
* System.out.println("Creating table " + tableId);
27+
* Field integerField = Field.of("fieldName", Field.Type.integer());
28+
* bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
29+
* } else {
30+
* System.out.println("Loading data into table " + tableId);
31+
* LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path");
32+
* loadJob = bigquery.create(loadJob);
33+
* while (loadJob.status().state() != JobStatus.State.DONE) {
34+
* Thread.sleep(1000L);
35+
* loadJob = bigquery.getJob(loadJob.jobId());
36+
* }
37+
* if (loadJob.status().error() != null) {
38+
* System.out.println("Job completed with errors");
39+
* } else {
40+
* System.out.println("Job succeeded");
41+
* }
42+
* }}</pre>
2443
*
2544
* @see <a href="https://cloud.google.com/bigquery/">Google Cloud BigQuery</a>
2645
*/

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";

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

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNull;
2122
import static org.junit.Assert.assertTrue;
2223

2324
import com.google.common.collect.ImmutableList;
@@ -45,6 +46,7 @@ public class InsertAllRequestTest {
4546
private static final BaseTableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_SCHEMA);
4647
private static final boolean SKIP_INVALID_ROWS = true;
4748
private static final boolean IGNORE_UNKNOWN_VALUES = false;
49+
private static final String TEMPLATE_SUFFIX = "templateSuffix";
4850
private static final InsertAllRequest INSERT_ALL_REQUEST1 = InsertAllRequest.builder(TABLE_ID)
4951
.addRow(CONTENT1)
5052
.addRow(CONTENT2)
@@ -90,20 +92,25 @@ public class InsertAllRequestTest {
9092
.ignoreUnknownValues(IGNORE_UNKNOWN_VALUES)
9193
.skipInvalidRows(SKIP_INVALID_ROWS)
9294
.build();
93-
private static final InsertAllRequest INSERT_ALL_REQUEST9 =
94-
InsertAllRequest.builder(TABLE_INFO)
95-
.addRow("id1", CONTENT1)
96-
.addRow("id2", CONTENT2)
97-
.ignoreUnknownValues(IGNORE_UNKNOWN_VALUES)
98-
.skipInvalidRows(SKIP_INVALID_ROWS)
99-
.build();
100-
private static final InsertAllRequest INSERT_ALL_REQUEST10 =
101-
InsertAllRequest.builder(TABLE_INFO)
102-
.addRow("id1", CONTENT1)
103-
.addRow("id2", CONTENT2)
104-
.ignoreUnknownValues(true)
105-
.skipInvalidRows(false)
106-
.build();
95+
private static final InsertAllRequest INSERT_ALL_REQUEST9 = InsertAllRequest.builder(TABLE_INFO)
96+
.addRow("id1", CONTENT1)
97+
.addRow("id2", CONTENT2)
98+
.ignoreUnknownValues(IGNORE_UNKNOWN_VALUES)
99+
.skipInvalidRows(SKIP_INVALID_ROWS)
100+
.build();
101+
private static final InsertAllRequest INSERT_ALL_REQUEST10 = InsertAllRequest.builder(TABLE_INFO)
102+
.addRow("id1", CONTENT1)
103+
.addRow("id2", CONTENT2)
104+
.ignoreUnknownValues(true)
105+
.skipInvalidRows(false)
106+
.build();
107+
private static final InsertAllRequest INSERT_ALL_REQUEST11 = InsertAllRequest.builder(TABLE_INFO)
108+
.addRow("id1", CONTENT1)
109+
.addRow("id2", CONTENT2)
110+
.ignoreUnknownValues(true)
111+
.skipInvalidRows(false)
112+
.templateSuffix(TEMPLATE_SUFFIX)
113+
.build();
107114

108115
@Test
109116
public void testBuilder() {
@@ -117,6 +124,7 @@ public void testBuilder() {
117124
assertEquals(TABLE_ID, INSERT_ALL_REQUEST8.table());
118125
assertEquals(TABLE_ID, INSERT_ALL_REQUEST9.table());
119126
assertEquals(TABLE_ID, INSERT_ALL_REQUEST10.table());
127+
assertEquals(TABLE_ID, INSERT_ALL_REQUEST11.table());
120128
assertEquals(ROWS, INSERT_ALL_REQUEST1.rows());
121129
assertEquals(ROWS, INSERT_ALL_REQUEST2.rows());
122130
assertEquals(ROWS, INSERT_ALL_REQUEST4.rows());
@@ -127,6 +135,7 @@ public void testBuilder() {
127135
assertEquals(ROWS_WITH_ID, INSERT_ALL_REQUEST8.rows());
128136
assertEquals(ROWS_WITH_ID, INSERT_ALL_REQUEST9.rows());
129137
assertEquals(ROWS_WITH_ID, INSERT_ALL_REQUEST10.rows());
138+
assertEquals(ROWS_WITH_ID, INSERT_ALL_REQUEST11.rows());
130139
assertEquals(SKIP_INVALID_ROWS, INSERT_ALL_REQUEST1.skipInvalidRows());
131140
assertEquals(SKIP_INVALID_ROWS, INSERT_ALL_REQUEST2.skipInvalidRows());
132141
assertEquals(SKIP_INVALID_ROWS, INSERT_ALL_REQUEST3.skipInvalidRows());
@@ -137,6 +146,7 @@ public void testBuilder() {
137146
assertEquals(SKIP_INVALID_ROWS, INSERT_ALL_REQUEST8.skipInvalidRows());
138147
assertEquals(SKIP_INVALID_ROWS, INSERT_ALL_REQUEST9.skipInvalidRows());
139148
assertFalse(INSERT_ALL_REQUEST10.skipInvalidRows());
149+
assertFalse(INSERT_ALL_REQUEST11.skipInvalidRows());
140150
assertEquals(IGNORE_UNKNOWN_VALUES, INSERT_ALL_REQUEST1.ignoreUnknownValues());
141151
assertEquals(IGNORE_UNKNOWN_VALUES, INSERT_ALL_REQUEST2.ignoreUnknownValues());
142152
assertEquals(IGNORE_UNKNOWN_VALUES, INSERT_ALL_REQUEST3.ignoreUnknownValues());
@@ -147,6 +157,18 @@ public void testBuilder() {
147157
assertEquals(IGNORE_UNKNOWN_VALUES, INSERT_ALL_REQUEST8.ignoreUnknownValues());
148158
assertEquals(IGNORE_UNKNOWN_VALUES, INSERT_ALL_REQUEST9.ignoreUnknownValues());
149159
assertTrue(INSERT_ALL_REQUEST10.ignoreUnknownValues());
160+
assertTrue(INSERT_ALL_REQUEST11.ignoreUnknownValues());
161+
assertNull(INSERT_ALL_REQUEST1.templateSuffix());
162+
assertNull(INSERT_ALL_REQUEST2.templateSuffix());
163+
assertNull(INSERT_ALL_REQUEST3.templateSuffix());
164+
assertNull(INSERT_ALL_REQUEST4.templateSuffix());
165+
assertNull(INSERT_ALL_REQUEST5.templateSuffix());
166+
assertNull(INSERT_ALL_REQUEST6.templateSuffix());
167+
assertNull(INSERT_ALL_REQUEST7.templateSuffix());
168+
assertNull(INSERT_ALL_REQUEST8.templateSuffix());
169+
assertNull(INSERT_ALL_REQUEST9.templateSuffix());
170+
assertNull(INSERT_ALL_REQUEST10.templateSuffix());
171+
assertEquals(TEMPLATE_SUFFIX, INSERT_ALL_REQUEST11.templateSuffix());
150172
}
151173

152174
@Test
@@ -183,6 +205,8 @@ public void testEquals() {
183205
compareInsertAllRequest(INSERT_ALL_REQUEST5, INSERT_ALL_REQUEST7);
184206
compareInsertAllRequest(INSERT_ALL_REQUEST7, INSERT_ALL_REQUEST8);
185207
compareInsertAllRequest(INSERT_ALL_REQUEST8, INSERT_ALL_REQUEST9);
208+
compareInsertAllRequest(INSERT_ALL_REQUEST10, INSERT_ALL_REQUEST10);
209+
compareInsertAllRequest(INSERT_ALL_REQUEST11, INSERT_ALL_REQUEST11);
186210
}
187211

188212
private void compareInsertAllRequest(InsertAllRequest expected, InsertAllRequest value) {
@@ -193,5 +217,6 @@ private void compareInsertAllRequest(InsertAllRequest expected, InsertAllRequest
193217
assertEquals(expected.rows(), value.rows());
194218
assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues());
195219
assertEquals(expected.skipInvalidRows(), value.skipInvalidRows());
220+
assertEquals(expected.templateSuffix(), value.templateSuffix());
196221
}
197222
}

branches/pubsub-alpha/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* A client to Google Cloud Resource Manager.
1919
*
2020
* <p>Here's a simple usage example for using gcloud-java-resourcemanager:
21-
* <pre>{@code
21+
* <pre> {@code
2222
* ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service();
2323
* String myProjectId = "my-globally-unique-project-id"; // Change to a unique project ID.
2424
* ProjectInfo myProject = resourceManager.create(ProjectInfo.builder(myProjectId).build());

branches/pubsub-alpha/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private static void writeResponse(HttpExchange exchange, Response response) {
185185
exchange.getResponseHeaders().set("Content-type", "application/json; charset=UTF-8");
186186
OutputStream outputStream = exchange.getResponseBody();
187187
try {
188+
exchange.getResponseHeaders().add("Connection", "close");
188189
exchange.sendResponseHeaders(response.code(), response.body().length());
189190
outputStream.write(response.body().getBytes(StandardCharsets.UTF_8));
190191
outputStream.close();

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* A client to Google Cloud Storage.
1919
*
2020
* <p>Here's a simple usage example for using gcloud-java from App/Compute Engine:
21-
* <pre>{@code
21+
* <pre> {@code
2222
* Storage storage = StorageOptions.defaultInstance().service();
2323
* BlobId blobId = BlobId.of("bucket", "blob_name");
2424
* Blob blob = Blob.load(storage, blobId);

0 commit comments

Comments
 (0)