Search in sources :

Example 1 with DatasetId

use of com.google.cloud.bigquery.DatasetId in project google-cloud-java by GoogleCloudPlatform.

the class ITBigQuerySnippets method testCreateGetAndDeleteDataset.

@Test
public void testCreateGetAndDeleteDataset() throws InterruptedException {
    DatasetId datasetId = DatasetId.of(bigquery.getOptions().getProjectId(), OTHER_DATASET);
    Dataset dataset = bigquerySnippets.createDataset(OTHER_DATASET);
    assertNotNull(dataset);
    assertEquals(datasetId, bigquerySnippets.getDataset(OTHER_DATASET).getDatasetId());
    assertNotNull(bigquerySnippets.updateDataset(OTHER_DATASET, "new friendly name"));
    assertEquals("new friendly name", bigquerySnippets.getDatasetFromId(datasetId.getProject(), OTHER_DATASET).getFriendlyName());
    Set<DatasetId> datasets = Sets.newHashSet(Iterators.transform(bigquerySnippets.listDatasets().iterateAll().iterator(), TO_DATASET_ID_FUNCTION));
    while (!datasets.contains(datasetId)) {
        Thread.sleep(500);
        datasets = Sets.newHashSet(Iterators.transform(bigquerySnippets.listDatasets().iterateAll().iterator(), TO_DATASET_ID_FUNCTION));
    }
    datasets = Sets.newHashSet(Iterators.transform(bigquerySnippets.listDatasets(datasetId.getProject()).iterateAll().iterator(), TO_DATASET_ID_FUNCTION));
    while (!datasets.contains(datasetId)) {
        Thread.sleep(500);
        datasets = Sets.newHashSet(Iterators.transform(bigquerySnippets.listDatasets(datasetId.getProject()).iterateAll().iterator(), TO_DATASET_ID_FUNCTION));
    }
    assertTrue(bigquerySnippets.deleteDataset(OTHER_DATASET));
    assertFalse(bigquerySnippets.deleteDatasetFromId(datasetId.getProject(), OTHER_DATASET));
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) DatasetId(com.google.cloud.bigquery.DatasetId) Test(org.junit.Test)

Example 2 with DatasetId

use of com.google.cloud.bigquery.DatasetId in project google-cloud-java by GoogleCloudPlatform.

the class BigQuerySnippets method getDatasetFromId.

/**
   * Example of getting a dataset.
   */
// [TARGET getDataset(DatasetId, DatasetOption...)]
// [VARIABLE "my_project_id"]
// [VARIABLE "my_dataset_name"]
public Dataset getDatasetFromId(String projectId, String datasetName) {
    // [START getDatasetFromId]
    DatasetId datasetId = DatasetId.of(projectId, datasetName);
    Dataset dataset = bigquery.getDataset(datasetId);
    // [END getDatasetFromId]
    return dataset;
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) DatasetId(com.google.cloud.bigquery.DatasetId)

Example 3 with DatasetId

use of com.google.cloud.bigquery.DatasetId in project google-cloud-java by GoogleCloudPlatform.

the class BigQuerySnippets method deleteDatasetFromId.

/**
   * Example of deleting a dataset, even if non-empty.
   */
// [TARGET delete(DatasetId, DatasetDeleteOption...)]
// [VARIABLE "my_project_id"]
// [VARIABLE "my_dataset_name"]
public Boolean deleteDatasetFromId(String projectId, String datasetName) {
    // [START deleteDatasetFromId]
    DatasetId datasetId = DatasetId.of(projectId, datasetName);
    Boolean deleted = bigquery.delete(datasetId, DatasetDeleteOption.deleteContents());
    if (deleted) {
    // the dataset was deleted
    } else {
    // the dataset was not found
    }
    // [END deleteDatasetFromId]
    return deleted;
}
Also used : DatasetId(com.google.cloud.bigquery.DatasetId)

Example 4 with DatasetId

use of com.google.cloud.bigquery.DatasetId in project google-cloud-java by GoogleCloudPlatform.

the class BigQuerySnippets method listTablesFromId.

/**
   * 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 listTablesFromId]
    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 listTablesFromId]
    return tables;
}
Also used : Table(com.google.cloud.bigquery.Table) DatasetId(com.google.cloud.bigquery.DatasetId)

Example 5 with DatasetId

use of com.google.cloud.bigquery.DatasetId in project java-docs-samples by GoogleCloudPlatform.

the class QuerySampleIT method deleteTestDataset.

private static final void deleteTestDataset() {
    BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
    DatasetId datasetId = DatasetId.of(TEST_DATASET);
    BigQuery.DatasetDeleteOption deleteContents = BigQuery.DatasetDeleteOption.deleteContents();
    bigquery.delete(datasetId, deleteContents);
}
Also used : BigQuery(com.google.cloud.bigquery.BigQuery) DatasetId(com.google.cloud.bigquery.DatasetId)

Aggregations

DatasetId (com.google.cloud.bigquery.DatasetId)15 BigQuery (com.google.cloud.bigquery.BigQuery)9 Dataset (com.google.cloud.bigquery.Dataset)3 Table (com.google.cloud.bigquery.Table)3 TableDefinition (com.google.cloud.bigquery.TableDefinition)2 TableId (com.google.cloud.bigquery.TableId)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 BIGQUERY_QUERY_FAILED_UNKNOWN (com.facebook.presto.plugin.bigquery.BigQueryErrorCode.BIGQUERY_QUERY_FAILED_UNKNOWN)1 DatasetDeleteOption (com.google.cloud.bigquery.BigQuery.DatasetDeleteOption)1 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 Job (com.google.cloud.bigquery.Job)1 JobInfo (com.google.cloud.bigquery.JobInfo)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)1 TableInfo (com.google.cloud.bigquery.TableInfo)1 TableResult (com.google.cloud.bigquery.TableResult)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterators (com.google.common.collect.Iterators)1