/** Example of listing tables in the dataset. */ // [TARGET list(TableListOption...)] public Page<Table> list() { // [START ] Page<Table> tables = dataset.list(); for (Table table : tables.iterateAll()) { // do something with the table } // [END ] return tables; }
@Test public void testList() throws Exception { initializeExpectedDataset(4); List<Table> tableResults = ImmutableList.of( new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); PageImpl<Table> expectedPage = new PageImpl<>(null, "c", tableResults); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.listTables(DATASET_INFO.getDatasetId())).andReturn(expectedPage); replay(bigquery); initializeDataset(); Page<Table> tablePage = dataset.list(); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); }
@Test public void testListWithOptions() throws Exception { initializeExpectedDataset(4); List<Table> tableResults = ImmutableList.of( new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); PageImpl<Table> expectedPage = new PageImpl<>(null, "c", tableResults); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.listTables(DATASET_INFO.getDatasetId(), BigQuery.TableListOption.pageSize(10L))) .andReturn(expectedPage); replay(bigquery); initializeDataset(); Page<Table> tablePage = dataset.list(BigQuery.TableListOption.pageSize(10L)); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); }
/** * Delete all the tables in the dataset and then delete the dataset */ public void forceDelete(Dataset dataset) { if (dataset != null) { List<Table> list = toList(dataset.list().iterateAll()); for (Table t : list) { t.delete(); } dataset.delete(); } }