/** * Returns a builder for an {@code InsertAllRequest} object given the destination table and the * rows to insert. */ public static Builder newBuilder(TableId table, RowToInsert... rows) { return newBuilder(table, ImmutableList.copyOf(rows)); }
final TableId tableId = request .getTable() .setProjectId( Strings.isNullOrEmpty(request.getTable().getProject()) ? getOptions().getProjectId() : request.getTable().getProject()); final TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest(); requestPb.setIgnoreUnknownValues(request.ignoreUnknownValues()); requestPb.setSkipInvalidRows(request.skipInvalidRows()); requestPb.setTemplateSuffix(request.getTemplateSuffix()); FluentIterable.from(request.getRows()) .transform( new Function<RowToInsert, Rows>() {
@Test public void testOf() { InsertAllRequest request = InsertAllRequest.of(TABLE_ID, ROWS); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_INFO, ROWS); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_ID.getDataset(), TABLE_ID.getTable(), ROWS); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_ID.getDataset(), TABLE_ID.getTable(), ROWS); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_ID, ROWS.get(0), ROWS.get(1)); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_INFO, ROWS.get(0), ROWS.get(1)); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); request = InsertAllRequest.of(TABLE_ID.getDataset(), TABLE_ID.getTable(), ROWS.get(0), ROWS.get(1)); assertThat(TABLE_ID).isEqualTo(request.getTable()); assertThat(ROWS).isEqualTo(request.getRows()); }
private void compareInsertAllRequest(InsertAllRequest expected, InsertAllRequest value) { assertThat(expected).isEqualTo(value); assertThat(expected.toString()).isEqualTo(value.toString()); assertThat(expected.hashCode()).isEqualTo(value.hashCode()); assertThat(expected.getTable()).isEqualTo(value.getTable()); assertThat(expected.getRows()).isEqualTo(value.getRows()); assertThat(expected.ignoreUnknownValues()).isEqualTo(value.ignoreUnknownValues()); assertThat(expected.skipInvalidRows()).isEqualTo(value.skipInvalidRows()); assertThat(expected.getTemplateSuffix()).isEqualTo(value.getTemplateSuffix()); } }
@Override public InsertAllResponse insertAll(InsertAllRequest request) { final TableId tableId = request.table(); final TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest(); requestPb.setIgnoreUnknownValues(request.ignoreUnknownValues()); requestPb.setSkipInvalidRows(request.skipInvalidRows()); requestPb.setTemplateSuffix(request.templateSuffix()); List<Rows> rowsPb = Lists.transform(request.rows(), new Function<RowToInsert, Rows>() { @Override public Rows apply(RowToInsert rowToInsert) { return new Rows().setInsertId(rowToInsert.id()).setJson(rowToInsert.content()); } }); requestPb.setRows(rowsPb); return InsertAllResponse.fromPb( bigQueryRpc.insertAll(tableId.dataset(), tableId.table(), requestPb)); }
return bigquery.insertAll(InsertAllRequest.of(getTableId(), rows));
/** Creates an {@code InsertAllRequest} object. */ public InsertAllRequest build() { return new InsertAllRequest(this); } }
@Test public void testPutWhenPartitioningOnMessageTime() { final String topic = "test-topic"; Map<String, String> properties = propertiesFactory.getProperties(); properties.put(BigQuerySinkConfig.TOPICS_CONFIG, topic); properties.put(BigQuerySinkConfig.DATASETS_CONFIG, ".*=scratch"); properties.put(BigQuerySinkTaskConfig.BIGQUERY_MESSAGE_TIME_PARTITIONING_CONFIG, "true"); BigQuery bigQuery = mock(BigQuery.class); Storage storage = mock(Storage.class); SinkTaskContext sinkTaskContext = mock(SinkTaskContext.class); InsertAllResponse insertAllResponse = mock(InsertAllResponse.class); when(bigQuery.insertAll(anyObject())).thenReturn(insertAllResponse); when(insertAllResponse.hasErrors()).thenReturn(false); BigQuerySinkTask testTask = new BigQuerySinkTask(bigQuery, null, storage); testTask.initialize(sinkTaskContext); testTask.start(properties); testTask.put(Collections.singletonList(spoofSinkRecord(topic, "value", "message text", TimestampType.CREATE_TIME, 1509007584334L))); testTask.flush(Collections.emptyMap()); ArgumentCaptor<InsertAllRequest> argument = ArgumentCaptor.forClass(InsertAllRequest.class); verify(bigQuery, times(1)).insertAll(argument.capture()); assertEquals("test-topic$20171026", argument.getValue().getTable().getTable()); }
/** * Insert rows into the table. * * @param rows rows to be inserted * @throws BigQueryException upon failure */ public InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows) throws BigQueryException { return bigquery.insertAll(InsertAllRequest.of(tableId(), rows)); }
/** Creates an {@code InsertAllRequest} object. */ public InsertAllRequest build() { return new InsertAllRequest(this); } }
/** * 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 newBuilder(datasetId, tableId, rows).build(); }
@Test public void testBuilder() { assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST1.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST2.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST3.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST4.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST5.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST6.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST7.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST8.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST9.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST10.getTable()); assertThat(TABLE_ID).isEqualTo(INSERT_ALL_REQUEST11.getTable()); assertThat(ROWS).isEqualTo(INSERT_ALL_REQUEST1.getRows()); assertThat(ROWS).isEqualTo(INSERT_ALL_REQUEST2.getRows()); assertThat(ROWS).isEqualTo(INSERT_ALL_REQUEST4.getRows()); assertThat(ROWS).isEqualTo(INSERT_ALL_REQUEST6.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST3.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST5.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST7.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST8.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST9.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST10.getRows()); assertThat(ROWS_WITH_ID).isEqualTo(INSERT_ALL_REQUEST11.getRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST1.skipInvalidRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST2.skipInvalidRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST3.skipInvalidRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST4.skipInvalidRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST5.skipInvalidRows()); assertThat(SKIP_INVALID_ROWS).isEqualTo(INSERT_ALL_REQUEST6.skipInvalidRows());
return bigquery.insertAll(InsertAllRequest.of(getTableId(), rows));
public InsertAllRequest build() { return new InsertAllRequest(this); } }
/** * Returns a builder for an {@code InsertAllRequest} object given the destination table and the * rows to insert. */ public static Builder newBuilder(TableId table, Iterable<RowToInsert> rows) { return newBuilder(table).setRows(rows); }
final TableId tableId = request .getTable() .setProjectId( Strings.isNullOrEmpty(request.getTable().getProject()) ? getOptions().getProjectId() : request.getTable().getProject()); final TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest(); requestPb.setIgnoreUnknownValues(request.ignoreUnknownValues()); requestPb.setSkipInvalidRows(request.skipInvalidRows()); requestPb.setTemplateSuffix(request.getTemplateSuffix()); FluentIterable.from(request.getRows()) .transform( new Function<RowToInsert, Rows>() {
/** * Returns a builder for an {@code InsertAllRequest} object given the destination table and the * rows to insert. */ public static Builder newBuilder(String datasetId, String tableId, RowToInsert... rows) { return newBuilder(TableId.of(datasetId, tableId), rows); }
/** * Returns a builder for an {@code InsertAllRequest} object given the destination table and the * rows to insert. */ public static Builder newBuilder(TableInfo tableInfo, RowToInsert... rows) { return newBuilder(tableInfo.getTableId(), rows); }
/** * 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(); }