Skip to content

Commit

Permalink
fix: update TableInsertRows.java
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
baeminbo committed Nov 13, 2023
1 parent 19b7c3a commit 224e805
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -39,12 +39,13 @@ public static void main(String[] args) {
Map<String, Object> rowContent = new HashMap<>();
rowContent.put("booleanField", true);
rowContent.put("numericField", "3.14");

// TODO(developer): Replace the row id with a unique value for each row.
String rowId = "ROW_ID";
tableInsertRows(datasetName, tableName, rowContent);
}

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

if (response.hasErrors()) {
Expand Down
Expand Up @@ -54,6 +54,8 @@ public static void tableInsertRowsWithoutRowIds(String datasetName, String table
InsertAllResponse response =
bigquery.insertAll(
InsertAllRequest.newBuilder(TableId.of(datasetName, tableName))
// No row ids disable de-duplication, and also disable the retries in the Java
// library.
.setRows(
ImmutableList.of(
InsertAllRequest.RowToInsert.of(rowContent1),
Expand Down

0 comments on commit 224e805

Please sign in to comment.