Search in sources :

Example 1 with TableList

use of com.google.api.services.bigquery.model.TableList in project google-cloud-java by GoogleCloudPlatform.

the class HttpBigQueryRpc method listTables.

@Override
public Tuple<String, Iterable<Table>> listTables(String projectId, String datasetId, Map<Option, ?> options) {
    try {
        TableList tableList = bigquery.tables().list(projectId, datasetId).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).execute();
        Iterable<TableList.Tables> tables = tableList.getTables();
        return Tuple.of(tableList.getNextPageToken(), Iterables.transform(tables != null ? tables : ImmutableList.<TableList.Tables>of(), new Function<TableList.Tables, Table>() {

            @Override
            public Table apply(TableList.Tables tablePb) {
                return new Table().setFriendlyName(tablePb.getFriendlyName()).setId(tablePb.getId()).setKind(tablePb.getKind()).setTableReference(tablePb.getTableReference()).setType(tablePb.getType());
            }
        }));
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : Function(com.google.common.base.Function) Table(com.google.api.services.bigquery.model.Table) TableList(com.google.api.services.bigquery.model.TableList) IOException(java.io.IOException)

Example 2 with TableList

use of com.google.api.services.bigquery.model.TableList in project beam by apache.

the class BigqueryClient method deleteDataset.

public void deleteDataset(String projectId, String datasetId) {
    try {
        TableList tables = bqClient.tables().list(projectId, datasetId).execute();
        for (Tables table : tables.getTables()) {
            this.deleteTable(projectId, datasetId, table.getTableReference().getTableId());
        }
    } catch (Exception e) {
        LOG.debug("Exceptions caught when listing all tables: " + e.getMessage());
    }
    try {
        bqClient.datasets().delete(projectId, datasetId).execute();
        LOG.info("Successfully deleted dataset: " + datasetId);
    } catch (Exception e) {
        LOG.debug("Exceptions caught when deleting dataset: " + e.getMessage());
    }
}
Also used : Tables(com.google.api.services.bigquery.model.TableList.Tables) TableList(com.google.api.services.bigquery.model.TableList) IOException(java.io.IOException)

Aggregations

TableList (com.google.api.services.bigquery.model.TableList)2 IOException (java.io.IOException)2 Table (com.google.api.services.bigquery.model.Table)1 Tables (com.google.api.services.bigquery.model.TableList.Tables)1 Function (com.google.common.base.Function)1