Skip to content

Commit ff4a086

Browse files
fix: update TableInsertRows.java (#2999)
* fix: update TableInsertRows.java Make the example set row id in `addRow`. If row id is missed, it disable the retry b/280865468, which I believe an unexpected behavior to users. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 19b7c3a commit ff4a086

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ If you are using Maven without the BOM, add this to your dependencies:
5353
If you are using Gradle 5.x or later, add this to your dependencies:
5454

5555
```Groovy
56-
implementation platform('com.google.cloud:libraries-bom:26.26.0')
56+
implementation platform('com.google.cloud:libraries-bom:26.27.0')
5757
5858
implementation 'com.google.cloud:google-cloud-bigquery'
5959
```

samples/snippets/src/main/java/com/example/bigquery/TableInsertRows.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ public static void main(String[] args) {
3939
Map<String, Object> rowContent = new HashMap<>();
4040
rowContent.put("booleanField", true);
4141
rowContent.put("numericField", "3.14");
42-
43-
tableInsertRows(datasetName, tableName, rowContent);
42+
// TODO(developer): Replace the row id with a unique value for each row.
43+
String rowId = "ROW_ID";
44+
tableInsertRows(datasetName, tableName, rowId, rowContent);
4445
}
4546

4647
public static void tableInsertRows(
47-
String datasetName, String tableName, Map<String, Object> rowContent) {
48+
String datasetName, String tableName, String rowId, Map<String, Object> rowContent) {
4849
try {
4950
// Initialize client that will be used to send requests. This client only needs to be created
5051
// once, and can be reused for multiple requests.
@@ -58,9 +59,8 @@ public static void tableInsertRows(
5859
bigquery.insertAll(
5960
InsertAllRequest.newBuilder(tableId)
6061
// More rows can be added in the same RPC by invoking .addRow() on the builder.
61-
// You can also supply optional unique row keys to support de-duplication
62-
// scenarios.
63-
.addRow(rowContent)
62+
// You can omit the unique row ids to disable de-duplication.
63+
.addRow(rowId, rowContent)
6464
.build());
6565

6666
if (response.hasErrors()) {

samples/snippets/src/main/java/com/example/bigquery/TableInsertRowsWithoutRowIds.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static void tableInsertRowsWithoutRowIds(String datasetName, String table
5454
InsertAllResponse response =
5555
bigquery.insertAll(
5656
InsertAllRequest.newBuilder(TableId.of(datasetName, tableName))
57+
// No row ids disable de-duplication, and also disable the retries in the Java
58+
// library.
5759
.setRows(
5860
ImmutableList.of(
5961
InsertAllRequest.RowToInsert.of(rowContent1),

samples/snippets/src/test/java/com/example/bigquery/TableInsertRowsIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ public void testTableInsertRows() {
8888
Map<String, Object> rowContent = new HashMap<>();
8989
rowContent.put("booleanField", true);
9090
rowContent.put("numericField", "3.14");
91+
String rowId = "ROW_ID";
9192
// Testing
92-
TableInsertRows.tableInsertRows(BIGQUERY_DATASET_NAME, tableName, rowContent);
93+
TableInsertRows.tableInsertRows(BIGQUERY_DATASET_NAME, tableName, rowId, rowContent);
9394
assertThat(bout.toString()).contains("Rows successfully inserted into table");
9495
}
9596
}

0 commit comments

Comments
 (0)