com.google.api.services.bigquery.Bigquery.Datasets

Here are the examples of the java api class com.google.api.services.bigquery.Bigquery.Datasets taken from open source projects.

1. DataflowExampleUtils#setupBigQueryTable()

Project: incubator-beam
File: DataflowExampleUtils.java
private void setupBigQueryTable(String projectId, String datasetId, String tableId, TableSchema schema) throws IOException {
    if (bigQueryClient == null) {
        bigQueryClient = Transport.newBigQueryClient(options.as(BigQueryOptions.class)).build();
    }
    Datasets datasetService = bigQueryClient.datasets();
    if (executeNullIfNotFound(datasetService.get(projectId, datasetId)) == null) {
        Dataset newDataset = new Dataset().setDatasetReference(new DatasetReference().setProjectId(projectId).setDatasetId(datasetId));
        datasetService.insert(projectId, newDataset).execute();
    }
    Tables tableService = bigQueryClient.tables();
    Table table = executeNullIfNotFound(tableService.get(projectId, datasetId, tableId));
    if (table == null) {
        Table newTable = new Table().setSchema(schema).setTableReference(new TableReference().setProjectId(projectId).setDatasetId(datasetId).setTableId(tableId));
        tableService.insert(projectId, datasetId, newTable).execute();
    } else if (!table.getSchema().equals(schema)) {
        throw new RuntimeException("Table exists and schemas do not match, expecting: " + schema.toPrettyString() + ", actual: " + table.getSchema().toPrettyString());
    }
}

2. DataflowExampleUtils#setupBigQueryTable()

Project: DataflowJavaSDK
File: DataflowExampleUtils.java
private void setupBigQueryTable(String projectId, String datasetId, String tableId, TableSchema schema) throws IOException {
    if (bigQueryClient == null) {
        bigQueryClient = Transport.newBigQueryClient(options.as(BigQueryOptions.class)).build();
    }
    Datasets datasetService = bigQueryClient.datasets();
    if (executeNullIfNotFound(datasetService.get(projectId, datasetId)) == null) {
        Dataset newDataset = new Dataset().setDatasetReference(new DatasetReference().setProjectId(projectId).setDatasetId(datasetId));
        datasetService.insert(projectId, newDataset).execute();
    }
    Tables tableService = bigQueryClient.tables();
    Table table = executeNullIfNotFound(tableService.get(projectId, datasetId, tableId));
    if (table == null) {
        Table newTable = new Table().setSchema(schema).setTableReference(new TableReference().setProjectId(projectId).setDatasetId(datasetId).setTableId(tableId));
        tableService.insert(projectId, datasetId, newTable).execute();
    } else if (!table.getSchema().equals(schema)) {
        throw new RuntimeException("Table exists and schemas do not match, expecting: " + schema.toPrettyString() + ", actual: " + table.getSchema().toPrettyString());
    }
}