while (true) { try { return insert.execute().getInsertErrors(); } catch (IOException e) { if (new ApiErrorExtractor().rateLimited(e)) {
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, datasetId, tableId, content).execute();
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)); }
/** * Streams data into BigQuery one record at a time without needing to run a load job. Requires the * WRITER dataset role. * * Create a request for the method "tabledata.insertAll". * * This request holds the parameters needed by the bigquery server. After setting any optional * parameters, call the {@link InsertAll#execute()} method to invoke the remote operation. * * @param projectId Project ID of the destination table. * @param datasetId Dataset ID of the destination table. * @param tableId Table ID of the destination table. * @param content the {@link com.google.api.services.bigquery.model.TableDataInsertAllRequest} * @return the request */ public InsertAll insertAll(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId, com.google.api.services.bigquery.model.TableDataInsertAllRequest content) throws java.io.IOException { InsertAll result = new InsertAll(projectId, datasetId, tableId, content); initialize(result); return result; }
public void insertDataToTable( String projectId, String datasetId, String tableName, List<Map<String, Object>> rows) { try { List<Rows> dataRows = rows.stream().map(row -> new Rows().setJson(row)).collect(Collectors.toList()); this.bqClient .tabledata() .insertAll( projectId, datasetId, tableName, new TableDataInsertAllRequest().setRows(dataRows)) .execute(); LOG.info("Successfully inserted data into table : " + tableName); } catch (Exception e) { LOG.debug("Exceptions caught when inserting data: " + e.getMessage()); } } }
@Override public TableDataInsertAllResponse insertAll( String projectId, String datasetId, String tableId, TableDataInsertAllRequest request) { try { return bigquery.tabledata().insertAll(projectId, datasetId, tableId, request).execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public TableDataInsertAllResponse insertAll(String datasetId, String tableId, TableDataInsertAllRequest request) { try { return bigquery.tabledata() .insertAll(this.options.projectId(), datasetId, tableId, request) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public TableDataInsertAllResponse insertAll(String datasetId, String tableId, TableDataInsertAllRequest request) { try { return bigquery.tabledata() .insertAll(this.options.projectId(), datasetId, tableId, request) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public TableDataInsertAllResponse insertAll( String projectId, String datasetId, String tableId, TableDataInsertAllRequest request) { try { return bigquery.tabledata().insertAll(projectId, datasetId, tableId, request).execute(); } catch (IOException ex) { throw translate(ex); } }