Search in sources :

Example 1 with Dataset

use of com.google.cloud.bigquery.Dataset 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 Dataset

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

the class ITDatasetSnippets method testReload.

@Test
public void testReload() {
    assertNull(dataset.getFriendlyName());
    Builder builder = dataset.toBuilder();
    builder.setFriendlyName(FRIENDLY_NAME);
    builder.build().update();
    Dataset reloadedDataset = datasetSnippets.reloadDataset();
    assertEquals(FRIENDLY_NAME, reloadedDataset.getFriendlyName());
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Builder(com.google.cloud.bigquery.Dataset.Builder) Test(org.junit.Test)

Example 3 with Dataset

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

the class ITBigQueryTest method testUpdateDataset.

@Test
public void testUpdateDataset() {
    Dataset dataset = bigquery.create(DatasetInfo.newBuilder(OTHER_DATASET).setDescription("Some Description").build());
    assertNotNull(dataset);
    assertEquals(bigquery.getOptions().getProjectId(), dataset.getDatasetId().getProject());
    assertEquals(OTHER_DATASET, dataset.getDatasetId().getDataset());
    assertEquals("Some Description", dataset.getDescription());
    Dataset updatedDataset = bigquery.update(dataset.toBuilder().setDescription("Updated Description").build());
    assertEquals("Updated Description", updatedDataset.getDescription());
    assertTrue(dataset.delete());
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Test(org.junit.Test)

Example 4 with Dataset

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

the class ITBigQueryTest method testGetDatasetWithSelectedFields.

@Test
public void testGetDatasetWithSelectedFields() {
    Dataset dataset = bigquery.getDataset(DATASET, DatasetOption.fields(DatasetField.CREATION_TIME, DatasetField.LABELS));
    assertEquals(bigquery.getOptions().getProjectId(), dataset.getDatasetId().getProject());
    assertEquals(DATASET, dataset.getDatasetId().getDataset());
    assertEquals(LABELS, dataset.getLabels());
    assertNotNull(dataset.getCreationTime());
    assertNull(dataset.getDescription());
    assertNull(dataset.getDefaultTableLifetime());
    assertNull(dataset.getAcl());
    assertNull(dataset.getEtag());
    assertNull(dataset.getFriendlyName());
    assertNull(dataset.getGeneratedId());
    assertNull(dataset.getLastModified());
    assertNull(dataset.getLocation());
    assertNull(dataset.getSelfLink());
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Test(org.junit.Test)

Example 5 with Dataset

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

the class ITBigQueryTest method testUpdateDatasetWithSelectedFields.

@Test
public void testUpdateDatasetWithSelectedFields() {
    Dataset dataset = bigquery.create(DatasetInfo.newBuilder(OTHER_DATASET).setDescription("Some Description").build());
    assertNotNull(dataset);
    assertEquals(bigquery.getOptions().getProjectId(), dataset.getDatasetId().getProject());
    assertEquals(OTHER_DATASET, dataset.getDatasetId().getDataset());
    assertEquals("Some Description", dataset.getDescription());
    Dataset updatedDataset = bigquery.update(dataset.toBuilder().setDescription("Updated Description").build(), DatasetOption.fields(DatasetField.DESCRIPTION));
    assertEquals("Updated Description", updatedDataset.getDescription());
    assertNull(updatedDataset.getCreationTime());
    assertNull(updatedDataset.getDefaultTableLifetime());
    assertNull(updatedDataset.getAcl());
    assertNull(updatedDataset.getEtag());
    assertNull(updatedDataset.getFriendlyName());
    assertNull(updatedDataset.getGeneratedId());
    assertNull(updatedDataset.getLastModified());
    assertNull(updatedDataset.getLocation());
    assertNull(updatedDataset.getSelfLink());
    assertTrue(dataset.delete());
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Test(org.junit.Test)

Aggregations

Dataset (com.google.cloud.bigquery.Dataset)11 Test (org.junit.Test)7 Builder (com.google.cloud.bigquery.Dataset.Builder)2 DatasetId (com.google.cloud.bigquery.DatasetId)2 DatasetInfo (com.google.cloud.bigquery.DatasetInfo)2 BigQueryException (com.google.cloud.bigquery.BigQueryException)1