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); } }
.setInsertErrors( ImmutableList.of( new TableDataInsertAllResponse.InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage"))))); EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) .andThrow(new BigQueryException(500, "InternalError"));
.setInsertErrors( ImmutableList.of( new InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout"))), new InsertErrors() .setIndex(1L) .setErrors(ImmutableList.of(new ErrorProto().setReason("invalid"))))); .setInsertErrors( ImmutableList.of( new InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout")))));
new TableDataInsertAllResponse.InsertErrors() .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout"))); TableDataInsertAllResponse.InsertErrors persistentError = new TableDataInsertAllResponse.InsertErrors() .setErrors(Lists.newArrayList(new ErrorProto().setReason("invalidQuery")));
.setInsertErrors(ImmutableList.of(new InsertErrors().setIndex(1L))); .setInsertErrors(ImmutableList.of(new InsertErrors().setIndex(0L)));
.setInsertErrors( ImmutableList.of( new InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout"))), new InsertErrors() .setIndex(1L) .setErrors(ImmutableList.of(new ErrorProto().setReason("invalid")))));
new TableDataInsertAllResponse.InsertErrors() .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout"))); TableDataInsertAllResponse.InsertErrors persistentError = new TableDataInsertAllResponse.InsertErrors() .setErrors(ImmutableList.of(new ErrorProto().setReason("invalidQuery")));
.setInsertErrors( ImmutableList.of( new InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout"))), new InsertErrors() .setIndex(1L) .setErrors(ImmutableList.of(new ErrorProto().setReason("invalid")))));
.setInsertErrors( ImmutableList.of( new InsertErrors().setIndex(1L).setErrors(ImmutableList.of(new ErrorProto()))));
new TableDataInsertAllResponse.InsertErrors() .setErrors(ImmutableList.of(new ErrorProto().setReason("timeout")));
int i = 0; for (InsertErrors errorSet : insertErrors) { for (ErrorProto singleError : errorSet.getErrors()) { String reason = singleError.getReason() + "~" + singleError.getMessage(); if (reasonCounts.get(reason) == null) {
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)); }
/** * Method to wrap a {@link BigQueryInsertError} into a {@link FailsafeElement}. * * @param insertError BigQueryInsert error. * @return FailsafeElement object. * @throws IOException */ private static FailsafeElement<String, String> wrapBigQueryInsertError( BigQueryInsertError insertError) { FailsafeElement<String, String> failsafeElement; try { failsafeElement = FailsafeElement.of( insertError.getRow().toPrettyString(), insertError.getRow().toPrettyString()); failsafeElement.setErrorMessage(insertError.getError().toPrettyString()); } catch (IOException e) { throw new RuntimeException(e); } return failsafeElement; }
@Test public void testDecodeEncodeEqual() throws Exception { BigQueryInsertError value = new BigQueryInsertError( new TableRow().setF(Collections.singletonList(new TableCell().setV("Value"))), new TableDataInsertAllResponse.InsertErrors() .setIndex(0L) .setErrors( Collections.singletonList( new ErrorProto() .setReason("a Reason") .setLocation("A location") .setMessage("A message") .setDebugInfo("The debug info"))), new TableReference() .setProjectId("dummy-project-id") .setDatasetId("dummy-dataset-id") .setTableId("dummy-table-id")); CoderProperties.coderDecodeEncodeEqual(TEST_CODER, value); } }
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; } }
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); } }
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); } }
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); } }