static InsertAllResponse fromPb(TableDataInsertAllResponse responsePb) { Map<Long, List<BigQueryError>> insertErrors = null; if (responsePb.getInsertErrors() != null) { List<InsertErrors> errorsPb = responsePb.getInsertErrors(); insertErrors = Maps.newHashMapWithExpectedSize(errorsPb.size()); for (InsertErrors errorPb : errorsPb) { insertErrors.put( errorPb.getIndex(), Lists.transform( errorPb.getErrors() != null ? errorPb.getErrors() : ImmutableList.<ErrorProto>of(), BigQueryError.FROM_PB_FUNCTION)); } } return new InsertAllResponse(insertErrors); } }
TableDataInsertAllResponse toPb() { TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse(); if (!insertErrors.isEmpty()) { responsePb.setInsertErrors( ImmutableList.copyOf( Iterables.transform( insertErrors.entrySet(), new Function<Map.Entry<Long, List<BigQueryError>>, InsertErrors>() { @Override public InsertErrors apply(Map.Entry<Long, List<BigQueryError>> entry) { return new InsertErrors() .setIndex(entry.getKey()) .setErrors( Lists.transform(entry.getValue(), BigQueryError.TO_PB_FUNCTION)); } }))); } return responsePb; }
new TableDataInsertAllResponse() .setInsertErrors( ImmutableList.of( new InsertErrors() wrapValue( new BigQueryInsertError( rows.get(0).getValue(), failures.getInsertErrors().get(0), ref)), wrapValue( new BigQueryInsertError( rows.get(1).getValue(), failures.getInsertErrors().get(1), ref)));
when(response.getContent()) .thenReturn(toStream(errorWithReasonAndStatus("rateLimitExceeded", 403))) .thenReturn(toStream(new TableDataInsertAllResponse()));
when(response.getContent()) .thenReturn(toStream(errorWithReasonAndStatus("actually forbidden", 403))) .thenReturn(toStream(new TableDataInsertAllResponse()));
.setTemplateSuffix("suffix"); TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse() .setInsertErrors( ImmutableList.of( new TableDataInsertAllResponse.InsertErrors()
static InsertAllResponse fromPb(TableDataInsertAllResponse responsePb) { Map<Long, List<BigQueryError>> insertErrors = null; if (responsePb.getInsertErrors() != null) { List<InsertErrors> errorsPb = responsePb.getInsertErrors(); insertErrors = Maps.newHashMapWithExpectedSize(errorsPb.size()); for (InsertErrors errorPb : errorsPb) { insertErrors.put(errorPb.getIndex(), Lists.transform( errorPb.getErrors() != null ? errorPb.getErrors() : ImmutableList.<ErrorProto>of(), BigQueryError.FROM_PB_FUNCTION)); } } return new InsertAllResponse(insertErrors); } }
ImmutableList.of(wrapValue(new TableRow()), wrapValue(new TableRow())); final TableDataInsertAllResponse allRowsSucceeded = new TableDataInsertAllResponse();
.setTemplateSuffix("suffix"); TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse() .setInsertErrors( ImmutableList.of( new TableDataInsertAllResponse.InsertErrors()
static InsertAllResponse fromPb(TableDataInsertAllResponse responsePb) { Map<Long, List<BigQueryError>> insertErrors = null; if (responsePb.getInsertErrors() != null) { List<InsertErrors> errorsPb = responsePb.getInsertErrors(); insertErrors = Maps.newHashMapWithExpectedSize(errorsPb.size()); for (InsertErrors errorPb : errorsPb) { insertErrors.put(errorPb.getIndex(), Lists.transform( errorPb.getErrors() != null ? errorPb.getErrors() : ImmutableList.<ErrorProto>of(), BigQueryError.FROM_PB_FUNCTION)); } } return new InsertAllResponse(insertErrors); } }
.setTemplateSuffix("suffix"); TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse() .setInsertErrors( ImmutableList.of( new TableDataInsertAllResponse.InsertErrors()
static InsertAllResponse fromPb(TableDataInsertAllResponse responsePb) { Map<Long, List<BigQueryError>> insertErrors = null; if (responsePb.getInsertErrors() != null) { List<InsertErrors> errorsPb = responsePb.getInsertErrors(); insertErrors = Maps.newHashMapWithExpectedSize(errorsPb.size()); for (InsertErrors errorPb : errorsPb) { insertErrors.put( errorPb.getIndex(), Lists.transform( errorPb.getErrors() != null ? errorPb.getErrors() : ImmutableList.<ErrorProto>of(), BigQueryError.FROM_PB_FUNCTION)); } } return new InsertAllResponse(insertErrors); } }
TableDataInsertAllResponse toPb() { TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse(); if (!insertErrors.isEmpty()) { responsePb.setInsertErrors(ImmutableList.copyOf(Iterables.transform(insertErrors.entrySet(), new Function<Map.Entry<Long, List<BigQueryError>>, InsertErrors>() { @Override public InsertErrors apply(Map.Entry<Long, List<BigQueryError>> entry) { return new InsertErrors() .setIndex(entry.getKey()) .setErrors(Lists.transform(entry.getValue(), BigQueryError.TO_PB_FUNCTION)); } }))); } return responsePb; }
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, datasetId, tableId, content).execute(); if (response.getInsertErrors() != null && response.getInsertErrors().size() > 0) { logInsertErrors(response.getInsertErrors(), rows);
TableDataInsertAllResponse toPb() { TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse(); if (!insertErrors.isEmpty()) { responsePb.setInsertErrors(ImmutableList.copyOf(Iterables.transform(insertErrors.entrySet(), new Function<Map.Entry<Long, List<BigQueryError>>, InsertErrors>() { @Override public InsertErrors apply(Map.Entry<Long, List<BigQueryError>> entry) { return new InsertErrors() .setIndex(entry.getKey()) .setErrors(Lists.transform(entry.getValue(), BigQueryError.TO_PB_FUNCTION)); } }))); } return responsePb; }
if (apiResponse.getInsertErrors() != null && !apiResponse.getInsertErrors().isEmpty()) { throw new Exception("InsertAll into " + tableId + " failed: " + apiResponse.getInsertErrors());
TableDataInsertAllResponse toPb() { TableDataInsertAllResponse responsePb = new TableDataInsertAllResponse(); if (!insertErrors.isEmpty()) { responsePb.setInsertErrors( ImmutableList.copyOf( Iterables.transform( insertErrors.entrySet(), new Function<Map.Entry<Long, List<BigQueryError>>, InsertErrors>() { @Override public InsertErrors apply(Map.Entry<Long, List<BigQueryError>> entry) { return new InsertErrors() .setIndex(entry.getKey()) .setErrors( Lists.transform(entry.getValue(), BigQueryError.TO_PB_FUNCTION)); } }))); } return responsePb; }
while (true) { try { return insert.execute().getInsertErrors(); } catch (IOException e) { if (new ApiErrorExtractor().rateLimited(e)) {
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( invocation -> { 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)); }
new TableDataInsertAllResponse() .setInsertErrors(ImmutableList.of(new InsertErrors().setIndex(1L))); new TableDataInsertAllResponse() .setInsertErrors(ImmutableList.of(new InsertErrors().setIndex(0L)));