Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.26.0')
implementation platform('com.google.cloud:libraries-bom:26.27.0')

implementation 'com.google.cloud:google-cloud-bigquery'
```
Expand Down
Original file line number Diff line number Diff line change
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");

tableInsertRows(datasetName, tableName, rowContent);
// TODO(developer): Replace the row id with a unique value for each row.
String rowId = "ROW_ID";
tableInsertRows(datasetName, tableName, rowId, 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ public void testTableInsertRows() {
Map<String, Object> rowContent = new HashMap<>();
rowContent.put("booleanField", true);
rowContent.put("numericField", "3.14");
String rowId = "ROW_ID";
// Testing
TableInsertRows.tableInsertRows(BIGQUERY_DATASET_NAME, tableName, rowContent);
TableInsertRows.tableInsertRows(BIGQUERY_DATASET_NAME, tableName, rowId, rowContent);
assertThat(bout.toString()).contains("Rows successfully inserted into table");
}
}