本文整理汇总了Java中com.google.api.services.bigquery.model.TableDataInsertAllResponse类的典型用法代码示例。如果您正苦于以下问题:Java TableDataInsertAllResponse类的具体用法?Java TableDataInsertAllResponse怎么用?Java TableDataInsertAllResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableDataInsertAllResponse类属于com.google.api.services.bigquery.model包,在下文中一共展示了TableDataInsertAllResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInsertRetry
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
/**
* Tests that {@link DatasetServiceImpl#insertAll} retries quota rate limited attempts.
*/
@Test
public void testInsertRetry() throws Exception {
TableReference ref =
new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table");
List<ValueInSingleWindow<TableRow>> rows = new ArrayList<>();
rows.add(wrapTableRow(new TableRow()));
// First response is 403 rate limited, second response has valid payload.
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(403).thenReturn(200);
when(response.getContent())
.thenReturn(toStream(errorWithReasonAndStatus("rateLimitExceeded", 403)))
.thenReturn(toStream(new TableDataInsertAllResponse()));
DatasetServiceImpl dataService =
new DatasetServiceImpl(bigquery, PipelineOptionsFactory.create());
dataService.insertAll(ref, rows, null,
BackOffAdapter.toGcpBackOff(TEST_BACKOFF.backoff()), new MockSleeper(),
InsertRetryPolicy.alwaysRetry(), null);
verify(response, times(2)).getStatusCode();
verify(response, times(2)).getContent();
verify(response, times(2)).getContentType();
expectedLogs.verifyInfo("BigQuery insertAll exceeded rate limit, retrying");
}
示例2: getInsertErrors
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
Map<TableRow, List<TableDataInsertAllResponse.InsertErrors>> getInsertErrors() {
Map<TableRow, List<TableDataInsertAllResponse.InsertErrors>> parsedInsertErrors =
Maps.newHashMap();
synchronized (tables) {
for (Map.Entry<String, List<String>> entry : this.insertErrors.entrySet()) {
TableRow tableRow = BigQueryHelpers.fromJsonString(entry.getKey(), TableRow.class);
List<TableDataInsertAllResponse.InsertErrors> allErrors = Lists.newArrayList();
for (String errorsString : entry.getValue()) {
allErrors.add(BigQueryHelpers.fromJsonString(
errorsString, TableDataInsertAllResponse.InsertErrors.class));
}
parsedInsertErrors.put(tableRow, allErrors);
}
}
return parsedInsertErrors;
}
示例3: before
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
@Before
public void before() throws Exception {
createTld("tld");
action = new VerifyEntityIntegrityAction();
action.mrRunner = new MapreduceRunner(Optional.of(2), Optional.of(2));
action.response = new FakeResponse();
BatchComponent component = mock(BatchComponent.class);
inject.setStaticField(VerifyEntityIntegrityAction.class, "component", component);
integrity =
new VerifyEntityIntegrityStreamer(
"project-id",
bigqueryFactory,
new Retrier(new FakeSleeper(new FakeClock()), 1),
Suppliers.ofInstance("rowid"),
now);
when(bigqueryFactory.create(anyString(), anyString(), anyString())).thenReturn(bigquery);
when(component.verifyEntityIntegrityStreamerFactory()).thenReturn(streamerFactory);
when(streamerFactory.create(any(DateTime.class))).thenReturn(integrity);
when(bigquery.tabledata()).thenReturn(bigqueryTableData);
rowsCaptor = ArgumentCaptor.forClass(TableDataInsertAllRequest.class);
when(bigqueryTableData.insertAll(anyString(), anyString(), anyString(), rowsCaptor.capture()))
.thenReturn(bigqueryInsertAll);
when(bigqueryInsertAll.execute()).thenReturn(new TableDataInsertAllResponse());
}
示例4: test
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
@Test
public void test() throws IOException {
String projectId = "";
String datasetId = "ontologies";
String tableId = "";
String timestamp = Long.toString((new Date()).getTime());
Bigquery bigquery = null;
TableRow row = new TableRow();
row.set("column_name", 7.7);
TableDataInsertAllRequest.Rows rows = new TableDataInsertAllRequest.Rows();
rows.setInsertId(timestamp);
rows.setJson(row);
List rowList =
new ArrayList();
rowList.add(rows);
TableDataInsertAllRequest content =
new TableDataInsertAllRequest().setRows(rowList);
TableDataInsertAllResponse response =
bigquery.tabledata().insertAll(
projectId, datasetId, tableId, content).execute();
}
示例5: main
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
public static void main(String[] args) throws IOException{
final Scanner scanner = new Scanner(System.in);
System.out.println("Enter your project id: ");
String projectId = scanner.nextLine();
System.out.println("Enter your dataset id: ");
String datasetId = scanner.nextLine();
System.out.println("Enter your table id: ");
String tableId = scanner.nextLine();
scanner.close();
System.out.println("Enter JSON to stream to BigQuery: \n"
+ "Press End-of-stream (CTRL-D) to stop");
JsonReader fromCLI = new JsonReader(new InputStreamReader(System.in));
Iterator<TableDataInsertAllResponse> responses = run(projectId,
datasetId,
tableId,
fromCLI);
while(responses.hasNext()){
System.out.println(responses.next());
}
fromCLI.close();
}
示例6: testStream
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
@Test
public void testStream() throws IOException{
JsonReader json = new JsonReader(
new FileReader(
new File(RESOURCE_PATH.resolve("streamrows.json").toString())));
Iterator<TableDataInsertAllResponse> response = StreamingSample.run(
CONSTANTS.getProjectId(),
CONSTANTS.getDatasetId(),
CONSTANTS.getCurrentTableId(),
json);
while(response.hasNext()){
assertTrue(!response.next().isEmpty());
}
}
示例7: run
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
public void run() {
try {
// Prepare target table
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date now = new Date();
String date = sdf.format(now);
String targetTable = filterId + "_results_" + date + "_v" + parent.TABLE_STRUCTURE_VERSION;
targetTable = targetTable.replace('-', '_');
parent.prepareTable(targetTable);
// Execute
TableDataInsertAllRequest ir = new TableDataInsertAllRequest().setRows(rows);
TableDataInsertAllResponse response = parent.bigquery.tabledata().insertAll(parent.projectId, parent.datasetId, targetTable, ir).execute();
List<TableDataInsertAllResponse.InsertErrors> errors = response.getInsertErrors();
if (errors != null) {
LOG.error(errors.size() + " error(s) while writing " + filterId + " to BigQuery");
} else {
// Log lines for debug
LOG.info(rows.size() + " lines written for " + filterId);
}
} catch (Exception e) {
LOG.error("Failed to write to BigQuery", e);
}
}
示例8: testInsertRetrySelectRows
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
/**
* Tests that {@link DatasetServiceImpl#insertAll} retries selected rows on failure.
*/
@Test
public void testInsertRetrySelectRows() throws Exception {
TableReference ref =
new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table");
List<ValueInSingleWindow<TableRow>> rows = ImmutableList.of(
wrapTableRow(new TableRow().set("row", "a")),
wrapTableRow(new TableRow().set("row", "b")));
List<String> insertIds = ImmutableList.of("a", "b");
final TableDataInsertAllResponse bFailed = new TableDataInsertAllResponse()
.setInsertErrors(ImmutableList.of(
new InsertErrors().setIndex(1L).setErrors(ImmutableList.of(new ErrorProto()))));
final TableDataInsertAllResponse allRowsSucceeded = new TableDataInsertAllResponse();
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200).thenReturn(200);
when(response.getContent())
.thenReturn(toStream(bFailed)).thenReturn(toStream(allRowsSucceeded));
DatasetServiceImpl dataService =
new DatasetServiceImpl(bigquery, PipelineOptionsFactory.create());
dataService.insertAll(ref, rows, insertIds,
BackOffAdapter.toGcpBackOff(TEST_BACKOFF.backoff()), new MockSleeper(),
InsertRetryPolicy.alwaysRetry(), null);
verify(response, times(2)).getStatusCode();
verify(response, times(2)).getContent();
verify(response, times(2)).getContentType();
}
示例9: testInsertDoesNotRetry
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
/**
* Tests that {@link DatasetServiceImpl#insertAll} does not retry non-rate-limited attempts.
*/
@Test
public void testInsertDoesNotRetry() throws Throwable {
TableReference ref =
new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table");
List<ValueInSingleWindow<TableRow>> rows = new ArrayList<>();
rows.add(wrapTableRow(new TableRow()));
// First response is 403 not-rate-limited, second response has valid payload but should not
// be invoked.
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(403).thenReturn(200);
when(response.getContent())
.thenReturn(toStream(errorWithReasonAndStatus("actually forbidden", 403)))
.thenReturn(toStream(new TableDataInsertAllResponse()));
thrown.expect(GoogleJsonResponseException.class);
thrown.expectMessage("actually forbidden");
DatasetServiceImpl dataService =
new DatasetServiceImpl(bigquery, PipelineOptionsFactory.create());
try {
dataService.insertAll(ref, rows, null,
BackOffAdapter.toGcpBackOff(TEST_BACKOFF.backoff()), new MockSleeper(),
InsertRetryPolicy.alwaysRetry(), null);
fail();
} catch (RuntimeException e) {
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
throw e.getCause();
}
}
示例10: generateErrorAmongMany
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
private TableDataInsertAllResponse.InsertErrors generateErrorAmongMany(
int numErrors, String baseReason, String exceptionalReason) {
// The retry policies are expected to search through the entire list of ErrorProtos to determine
// whether to retry. Stick the exceptionalReason in a random position to exercise this.
List<ErrorProto> errorProtos = Lists.newArrayListWithExpectedSize(numErrors);
int exceptionalPosition = ThreadLocalRandom.current().nextInt(numErrors);
for (int i = 0; i < numErrors; ++i) {
ErrorProto error = new ErrorProto();
error.setReason((i == exceptionalPosition) ? exceptionalReason : baseReason);
errorProtos.add(error);
}
TableDataInsertAllResponse.InsertErrors errors = new TableDataInsertAllResponse.InsertErrors();
errors.setErrors(errorProtos);
return errors;
}
示例11: onInsertAll
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
private void onInsertAll(List<List<Long>> errorIndicesSequence) throws Exception {
when(mockClient.tabledata())
.thenReturn(mockTabledata);
final List<TableDataInsertAllResponse> responses = new ArrayList<>();
for (List<Long> errorIndices : errorIndicesSequence) {
List<TableDataInsertAllResponse.InsertErrors> errors = new ArrayList<>();
for (long i : errorIndices) {
TableDataInsertAllResponse.InsertErrors error =
new TableDataInsertAllResponse.InsertErrors();
error.setIndex(i);
}
TableDataInsertAllResponse response = new TableDataInsertAllResponse();
response.setInsertErrors(errors);
responses.add(response);
}
doAnswer(
new Answer<Bigquery.Tabledata.InsertAll>() {
@Override
public Bigquery.Tabledata.InsertAll answer(InvocationOnMock invocation) throws Throwable {
Bigquery.Tabledata.InsertAll mockInsertAll = mock(Bigquery.Tabledata.InsertAll.class);
when(mockInsertAll.execute())
.thenReturn(responses.get(0),
responses.subList(1, responses.size()).toArray(
new TableDataInsertAllResponse[responses.size() - 1]));
return mockInsertAll;
}
})
.when(mockTabledata)
.insertAll(anyString(), anyString(), anyString(), any(TableDataInsertAllRequest.class));
}
示例12: failOnInsert
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
/**
* Cause a given {@link TableRow} object to fail when it's inserted. The errors link the list
* will be returned on subsequent retries, and the insert will succeed when the errors run out.
*/
public void failOnInsert(
Map<TableRow, List<TableDataInsertAllResponse.InsertErrors>> insertErrors) {
synchronized (tables) {
for (Map.Entry<TableRow, List<TableDataInsertAllResponse.InsertErrors>> entry
: insertErrors.entrySet()) {
List<String> errorStrings = Lists.newArrayList();
for (TableDataInsertAllResponse.InsertErrors errors : entry.getValue()) {
errorStrings.add(BigQueryHelpers.toJsonString(errors));
}
this.insertErrors.put(BigQueryHelpers.toJsonString(entry.getKey()), errorStrings);
}
}
}
示例13: testFailuresNoRetryPolicy
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
@Test
public void testFailuresNoRetryPolicy() throws Exception {
TableRow row1 = new TableRow().set("name", "a").set("number", "1");
TableRow row2 = new TableRow().set("name", "b").set("number", "2");
TableRow row3 = new TableRow().set("name", "c").set("number", "3");
TableDataInsertAllResponse.InsertErrors ephemeralError =
new TableDataInsertAllResponse.InsertErrors().setErrors(
ImmutableList.of(new ErrorProto().setReason("timeout")));
fakeDatasetService.failOnInsert(
ImmutableMap.<TableRow, List<TableDataInsertAllResponse.InsertErrors>>of(
row1, ImmutableList.of(ephemeralError, ephemeralError),
row2, ImmutableList.of(ephemeralError, ephemeralError)));
p.apply(Create.of(row1, row2, row3))
.apply(
BigQueryIO.writeTableRows()
.to("project-id:dataset-id.table-id")
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withMethod(BigQueryIO.Write.Method.STREAMING_INSERTS)
.withSchema(
new TableSchema()
.setFields(
ImmutableList.of(
new TableFieldSchema().setName("name").setType("STRING"),
new TableFieldSchema().setName("number").setType("INTEGER"))))
.withTestServices(fakeBqServices)
.withoutValidation());
p.run();
assertThat(
fakeDatasetService.getAllRows("project-id", "dataset-id", "table-id"),
containsInAnyOrder(row1, row2, row3));
}
示例14: testRetryPolicy
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
@Test
public void testRetryPolicy() throws Exception {
TableRow row1 = new TableRow().set("name", "a").set("number", "1");
TableRow row2 = new TableRow().set("name", "b").set("number", "2");
TableRow row3 = new TableRow().set("name", "c").set("number", "3");
TableDataInsertAllResponse.InsertErrors ephemeralError =
new TableDataInsertAllResponse.InsertErrors().setErrors(
ImmutableList.of(new ErrorProto().setReason("timeout")));
TableDataInsertAllResponse.InsertErrors persistentError =
new TableDataInsertAllResponse.InsertErrors().setErrors(
ImmutableList.of(new ErrorProto().setReason("invalidQuery")));
fakeDatasetService.failOnInsert(
ImmutableMap.<TableRow, List<TableDataInsertAllResponse.InsertErrors>>of(
row1, ImmutableList.of(ephemeralError, ephemeralError),
row2, ImmutableList.of(ephemeralError, ephemeralError, persistentError)));
PCollection<TableRow> failedRows =
p.apply(Create.of(row1, row2, row3))
.apply(BigQueryIO.writeTableRows().to("project-id:dataset-id.table-id")
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withMethod(BigQueryIO.Write.Method.STREAMING_INSERTS)
.withSchema(new TableSchema().setFields(
ImmutableList.of(
new TableFieldSchema().setName("name").setType("STRING"),
new TableFieldSchema().setName("number").setType("INTEGER"))))
.withFailedInsertRetryPolicy(InsertRetryPolicy.retryTransientErrors())
.withTestServices(fakeBqServices)
.withoutValidation()).getFailedInserts();
// row2 finally fails with a non-retryable error, so we expect to see it in the collection of
// failed rows.
PAssert.that(failedRows).containsInAnyOrder(row2);
p.run();
// Only row1 and row3 were successfully inserted.
assertThat(
fakeDatasetService.getAllRows("project-id", "dataset-id", "table-id"),
containsInAnyOrder(row1, row3));
}
示例15: streamRow
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; //导入依赖的package包/类
public static TableDataInsertAllResponse streamRow(Bigquery bigquery,
String projectId,
String datasetId,
String tableId,
TableDataInsertAllRequest.Rows row) throws IOException{
return bigquery.tabledata().insertAll(
projectId,
datasetId,
tableId,
new TableDataInsertAllRequest().setRows(Collections.singletonList(row))).execute();
}