InsertAllRequest request = InsertAllRequest.newBuilder(tableInfo.getTableId()) .addRow(builder1.build()) .addRow(builder2.build()) .addRow(builder3.build()) .setSkipInvalidRows(true) .build(); InsertAllResponse response = bigquery.insertAll(request); assertTrue(response.hasErrors());
InsertAllRequest request = InsertAllRequest.newBuilder(TABLE_ID) .setRows(rows) .setSkipInvalidRows(false) .setIgnoreUnknownValues(true) .setTemplateSuffix("suffix") .build(); TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest()
InsertAllRequest request = InsertAllRequest.newBuilder(getTableId(), rows) .setSkipInvalidRows(skipInvalidRows) .setIgnoreUnknownValues(ignoreUnknownValues) .build(); return bigquery.insertAll(request);
/** * Adds a row to be inserted without an associated id. Please notice that data for fields of * type {@link LegacySQLTypeName#BYTES} must be provided as a base64 encoded string. * * <p>Example usage of adding a row without an associated id: * * <pre>{@code * InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId); * List<Long> repeatedFieldValue = Arrays.asList(1L, 2L); * Map<String, Object> recordContent = new HashMap<String, Object>(); * recordContent.put("subfieldName1", "value"); * recordContent.put("subfieldName2", repeatedFieldValue); * Map<String, Object> rowContent = new HashMap<String, Object>(); * rowContent.put("booleanFieldName", true); * rowContent.put("bytesFieldName", "DQ4KDQ=="); * rowContent.put("recordFieldName", recordContent); * builder.addRow(rowContent); * }</pre> */ public Builder addRow(Map<String, ?> content) { addRow(new RowToInsert(null, content)); return this; }
/** * Adds a row to be inserted with associated id. Please notice that data for fields of type * {@link Field.Type#bytes()} must be provided as a base64 encoded string. * * <p>Example usage of adding a row with associated id: * <pre> {@code * InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId); * List<Long> repeatedFieldValue = Arrays.asList(1L, 2L); * Map<String, Object> recordContent = new HashMap<String, Object>(); * recordContent.put("subfieldName1", "value"); * recordContent.put("subfieldName2", repeatedFieldValue); * Map<String, Object> rowContent = new HashMap<String, Object>(); * rowContent.put("booleanFieldName", true); * rowContent.put("bytesFieldName", "DQ4KDQ=="); * rowContent.put("recordFieldName", recordContent); * builder.addRow("rowId", rowContent); * }</pre> */ public Builder addRow(String id, Map<String, Object> content) { addRow(new RowToInsert(id, content)); return this; }
/** * Adds a row to be inserted with associated id. Please notice that data for fields of type * {@link LegacySQLTypeName#BYTES} must be provided as a base64 encoded string. * * <p>Example usage of adding a row with associated id: * * <pre>{@code * InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId); * List<Long> repeatedFieldValue = Arrays.asList(1L, 2L); * Map<String, Object> recordContent = new HashMap<String, Object>(); * recordContent.put("subfieldName1", "value"); * recordContent.put("subfieldName2", repeatedFieldValue); * Map<String, Object> rowContent = new HashMap<String, Object>(); * rowContent.put("booleanFieldName", true); * rowContent.put("bytesFieldName", "DQ4KDQ=="); * rowContent.put("recordFieldName", recordContent); * builder.addRow("rowId", rowContent); * }</pre> */ public Builder addRow(String id, Map<String, ?> content) { addRow(new RowToInsert(id, content)); return this; }
/** * Adds a row to be inserted without an associated id. Please notice that data for fields of * type {@link Field.Type#bytes()} must be provided as a base64 encoded string. * * <p>Example usage of adding a row without an associated id: * <pre> {@code * InsertAllRequest.Builder builder = InsertAllRequest.builder(tableId); * List<Long> repeatedFieldValue = Arrays.asList(1L, 2L); * Map<String, Object> recordContent = new HashMap<String, Object>(); * recordContent.put("subfieldName1", "value"); * recordContent.put("subfieldName2", repeatedFieldValue); * Map<String, Object> rowContent = new HashMap<String, Object>(); * rowContent.put("booleanFieldName", true); * rowContent.put("bytesFieldName", "DQ4KDQ=="); * rowContent.put("recordFieldName", recordContent); * builder.addRow(rowContent); * }</pre> */ public Builder addRow(Map<String, Object> content) { addRow(new RowToInsert(null, content)); return this; }
/** * Insert rows into the table. * * @param rows rows to be inserted * @param skipInvalidRows whether to insert all valid rows, even if invalid rows exist. If not set * the entire insert operation will fail if rows to be inserted contain an invalid row * @param ignoreUnknownValues whether to accept rows that contain values that do not match the * schema. The unknown values are ignored. If not set, rows with unknown values are considered * to be invalid * @throws BigQueryException upon failure */ public InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows, boolean skipInvalidRows, boolean ignoreUnknownValues) throws BigQueryException { InsertAllRequest request = InsertAllRequest.builder(tableId(), rows) .skipInvalidRows(skipInvalidRows) .ignoreUnknownValues(ignoreUnknownValues) .build(); return bigquery.insertAll(request); }
/** * Utility method for spoofing InsertAllRequests that should be sent to a BigQuery object. * @param table The table to write to. * @param rows The rows to write. * @return The spoofed InsertAllRequest. */ public static InsertAllRequest buildExpectedInsertAllRequest( TableId table, InsertAllRequest.RowToInsert... rows) { return InsertAllRequest.newBuilder(table, rows) .setIgnoreUnknownValues(false) .setSkipInvalidRows(false) .build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(String datasetId, String tableId, Iterable<RowToInsert> rows) { return builder(datasetId, tableId, rows).build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(TableId tableId, RowToInsert... rows) { return builder(tableId, rows).build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(TableInfo tableInfo, Iterable<RowToInsert> rows) { return newBuilder(tableInfo.getTableId(), rows).build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(TableId tableId, RowToInsert... rows) { return newBuilder(tableId, rows).build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(TableId tableId, Iterable<RowToInsert> rows) { return newBuilder(tableId, rows).build(); }
/** * Create an InsertAllRequest. * @param tableId the table to insert into. * @param rows the rows to insert. * @return the InsertAllRequest. */ protected InsertAllRequest createInsertAllRequest(PartitionedTableId tableId, List<InsertAllRequest.RowToInsert> rows) { return InsertAllRequest.newBuilder(tableId.getFullTableId(), rows) .setIgnoreUnknownValues(false) .setSkipInvalidRows(false) .build(); }
/** Inserts multiple rows of the same schema to a BigQuery table. */ public void insertAll(Collection<Map<String, ?>> rows, String table) { TableId tableId = TableId.of(projectId, dataset, table); InsertAllRequest.Builder builder = InsertAllRequest.newBuilder(tableId); for (Map<String, ?> row : rows) { builder.addRow(row); } InsertAllResponse response = client.insertAll(builder.build()); handleBigQueryResponseExceptions(response); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(TableInfo tableInfo, Iterable<RowToInsert> rows) { return builder(tableInfo.tableId(), rows).build(); }
/** * Returns a {@code InsertAllRequest} object given the destination table and the rows to insert. */ public static InsertAllRequest of(String datasetId, String tableId, RowToInsert... rows) { return newBuilder(datasetId, tableId, rows).build(); }