Search in sources :

Example 11 with InsertAllResponse

use of com.google.cloud.bigquery.InsertAllResponse in project google-cloud-java by GoogleCloudPlatform.

the class TableSnippets method insert.

/**
   * Example of inserting rows into the table.
   */
// [TARGET insert(Iterable)]
// [VARIABLE "rowId1"]
// [VARIABLE "rowId2"]
public InsertAllResponse insert(String rowId1, String rowId2) {
    // [START insert]
    List<RowToInsert> rows = new ArrayList<>();
    Map<String, Object> row1 = new HashMap<>();
    row1.put("stringField", "value1");
    row1.put("booleanField", true);
    Map<String, Object> row2 = new HashMap<>();
    row2.put("stringField", "value2");
    row2.put("booleanField", false);
    rows.add(RowToInsert.of(rowId1, row1));
    rows.add(RowToInsert.of(rowId2, row2));
    InsertAllResponse response = table.insert(rows);
    // [END insert]
    return response;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RowToInsert(com.google.cloud.bigquery.InsertAllRequest.RowToInsert) InsertAllResponse(com.google.cloud.bigquery.InsertAllResponse)

Aggregations

InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)11 Test (org.junit.Test)7 InsertAllRequest (com.google.cloud.bigquery.InsertAllRequest)4 StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)4 TableInfo (com.google.cloud.bigquery.TableInfo)4 HashMap (java.util.HashMap)4 List (java.util.List)4 FieldValue (com.google.cloud.bigquery.FieldValue)3 TableId (com.google.cloud.bigquery.TableId)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 RowToInsert (com.google.cloud.bigquery.InsertAllRequest.RowToInsert)2 Schema (com.google.cloud.bigquery.Schema)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 BigQuery (com.google.cloud.bigquery.BigQuery)1 Field (com.google.cloud.bigquery.Field)1 QueryRequest (com.google.cloud.bigquery.QueryRequest)1 QueryResponse (com.google.cloud.bigquery.QueryResponse)1 Table (com.google.cloud.bigquery.Table)1 Function (com.google.common.base.Function)1