@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 TableDataList listTableData( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tabledata() .list(projectId, datasetId, tableId) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setStartIndex( Option.START_INDEX.getLong(options) != null ? BigInteger.valueOf(Option.START_INDEX.getLong(options)) : null) .execute(); } catch (IOException ex) { throw translate(ex); } }
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()); } } }
private void verifyInsertAll(int expectedRetries) throws IOException { verify(mockClient, times(expectedRetries)).tabledata(); verify(mockTabledata, times(expectedRetries)) .insertAll(anyString(), anyString(), anyString(), any(TableDataInsertAllRequest.class)); }
@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); } }
private void onTableList(TableDataList result) throws IOException { when(mockClient.tabledata()).thenReturn(mockTabledata); when(mockTabledata.list(anyString(), anyString(), anyString())).thenReturn(mockTabledataList); when(mockTabledataList.execute()).thenReturn(result); }
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, datasetId, tableId, content).execute();
@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); } }
@VisibleForTesting boolean isTableEmpty(TableReference tableRef, BackOff backoff, Sleeper sleeper) throws IOException, InterruptedException { TableDataList dataList = executeWithRetries( client .tabledata() .list(tableRef.getProjectId(), tableRef.getDatasetId(), tableRef.getTableId()), String.format( "Unable to list table data: %s, aborting after %d retries.", tableRef.getTableId(), MAX_RPC_RETRIES), sleeper, backoff, DONT_RETRY_NOT_FOUND); return dataList.getRows() == null || dataList.getRows().isEmpty(); }
.tabledata() .insertAll(configuration.getProjectId(), configuration.getDatasetId(),
private List<TableRow> getTableRows(Bigquery bq) { try { return bq.tabledata() .list( pipelineOptions.getProject(), pipelineOptions.getTargetDataset(), table.getTableReference().getTableId()) .execute() .getRows(); } catch (IOException e) { throw new RuntimeException(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)); }
rowList.add(rows); TableDataInsertAllRequest content = new TableDataInsertAllRequest().setRows(rowList); TableDataInsertAllResponse response = bigquery.tabledata().insertAll(PROJECT_ID, DATASET_ID, TABLE_ID, content).execute(); System.out.println("Final response = " + response);
client.tabledata().list(ref.getProjectId(), ref.getDatasetId(), ref.getTableId()); if (pageToken != null) { list.setPageToken(pageToken);
@Override public TableDataList listTableData( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tabledata() .list(projectId, datasetId, tableId) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setStartIndex( Option.START_INDEX.getLong(options) != null ? BigInteger.valueOf(Option.START_INDEX.getLong(options)) : null) .execute(); } catch (IOException ex) { throw translate(ex); } }
.tabledata() .insertAll(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), content);
@Override public Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String tableId, Map<Option, ?> options) { try { TableDataList tableDataList = bigquery.tabledata() .list(this.options.projectId(), datasetId, tableId) .setMaxResults(MAX_RESULTS.getLong(options)) .setPageToken(PAGE_TOKEN.getString(options)) .setStartIndex(START_INDEX.getLong(options) != null ? BigInteger.valueOf(START_INDEX.getLong(options)) : null) .execute(); return Tuple.<String, Iterable<TableRow>>of(tableDataList.getPageToken(), tableDataList.getRows()); } catch (IOException ex) { throw translate(ex); } }
@Override public Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String tableId, Map<Option, ?> options) { try { TableDataList tableDataList = bigquery.tabledata() .list(this.options.projectId(), datasetId, tableId) .setMaxResults(MAX_RESULTS.getLong(options)) .setPageToken(PAGE_TOKEN.getString(options)) .setStartIndex(START_INDEX.getLong(options) != null ? BigInteger.valueOf(START_INDEX.getLong(options)) : null) .execute(); return Tuple.<String, Iterable<TableRow>>of(tableDataList.getPageToken(), tableDataList.getRows()); } catch (IOException ex) { throw translate(ex); } }