@Override public void run(BigQuery bigquery, DatasetId datasetId) { for (Table table : bigquery.listTables(datasetId).iterateAll()) { System.out.println(table); } } }
/** * Returns the paginated list of tables in this dataset. * * <p>Example of listing tables in the dataset. * * <pre>{@code * Page<Table> tables = dataset.list(); * for (Table table : tables.iterateAll()) { * // do something with the table * } * }</pre> * * @param options options for listing tables * @throws BigQueryException upon failure */ public Page<Table> list(TableListOption... options) { return bigquery.listTables(getDatasetId(), options); }
/** Example of listing the tables in a dataset, specifying the page size. */ // [TARGET listTables(String, TableListOption...)] // [VARIABLE "my_dataset_name"] public Page<Table> listTables(String datasetName) { // [START ] Page<Table> tables = bigquery.listTables(datasetName, TableListOption.pageSize(100)); for (Table table : tables.iterateAll()) { // do something with the table } // [END ] return tables; }
/** Example of listing the tables in a dataset. */ // [TARGET listTables(DatasetId, TableListOption...)] // [VARIABLE "my_project_id"] // [VARIABLE "my_dataset_name"] public Page<Table> listTablesFromId(String projectId, String datasetName) { // [START bigquery_list_tables] DatasetId datasetId = DatasetId.of(projectId, datasetName); Page<Table> tables = bigquery.listTables(datasetId, TableListOption.pageSize(100)); for (Table table : tables.iterateAll()) { // do something with the table } // [END bigquery_list_tables] return tables; }
@Test public void testListTablesFromDatasetIdWithProject() { bigquery = options.getService(); ImmutableList<Table> tableList = ImmutableList.of( new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO.setProjectId(OTHER_PROJECT)))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); EasyMock.expect(bigqueryRpcMock.listTables(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Table> page = bigquery.listTables(DatasetId.of(OTHER_PROJECT, DATASET)); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); }
@Test public void testListTablesWithOptions() { bigquery = options.getService(); ImmutableList<Table> tableList = ImmutableList.of( new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Table> page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); }
@Test public void testListTablesFromDatasetId() { bigquery = options.getService(); ImmutableList<Table> tableList = ImmutableList.of( new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Table> page = bigquery.listTables(DatasetId.of(DATASET)); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); }
@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 testListTables() { bigquery = options.getService(); ImmutableList<Table> tableList = ImmutableList.of( new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO)), new Table(bigquery, new TableInfo.BuilderImpl(MODEL_TABLE_INFO_WITH_PROJECT))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Table> page = bigquery.listTables(DATASET); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); }
@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()); }
@Test public void testListTables() { String tableName = "test_list_tables"; StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); Table createdTable = bigquery.create(tableInfo); assertNotNull(createdTable); Page<Table> tables = bigquery.listTables(DATASET); boolean found = false; Iterator<Table> tableIterator = tables.getValues().iterator(); while (tableIterator.hasNext() && !found) { if (tableIterator.next().getTableId().equals(createdTable.getTableId())) { found = true; } } assertTrue(found); assertTrue(createdTable.delete()); }
/** * Returns the paginated list of tables in this dataset. * * @param options options for listing tables * @throws BigQueryException upon failure */ public Page<Table> list(BigQuery.TableListOption... options) { return bigquery.listTables(datasetId(), options); }
/** * Returns the paginated list of tables in this dataset. * * <p>Example of listing tables in the dataset. * * <pre>{@code * Page<Table> tables = dataset.list(); * for (Table table : tables.iterateAll()) { * // do something with the table * } * }</pre> * * @param options options for listing tables * @throws BigQueryException upon failure */ public Page<Table> list(TableListOption... options) { return bigquery.listTables(getDatasetId(), options); }
@Override public Set<String> listTables() throws IOException { BigQuery bigquery = BigQueryConnection.createClient(properties.getDatastoreProperties()); DatasetId datasetId = DatasetId.of(properties.getDatastoreProperties().projectName.getValue(), properties.bqDataset.getValue()); Page<Table> tables = bigquery.listTables(datasetId, BigQuery.TableListOption.pageSize(100)); Set<String> tablesName = new HashSet<>(); Iterator<Table> tableIterator = tables.iterateAll().iterator(); while (tableIterator.hasNext()) { tablesName.add(tableIterator.next().getTableId().getTable()); } return tablesName; }
@Override public Set<String> listTables() throws IOException { BigQuery bigquery = BigQueryConnection.createClient(properties.getDatastoreProperties()); DatasetId datasetId = DatasetId.of(properties.getDatastoreProperties().projectName.getValue(), properties.bqDataset.getValue()); Page<Table> tables = bigquery.listTables(datasetId, BigQuery.TableListOption.pageSize(100)); Set<String> tablesName = new HashSet<>(); Iterator<Table> tableIterator = tables.iterateAll().iterator(); while (tableIterator.hasNext()) { tablesName.add(tableIterator.next().getTableId().getTable()); } return tablesName; }