Search in sources :

Example 6 with Dataset

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

the class DatasetSnippets method updateDataset.

/**
   * Example of updating a dataset.
   */
// [TARGET update(DatasetOption...)]
// [VARIABLE "my_friendly_name"]
public Dataset updateDataset(String friendlyName) {
    // [START update]
    Builder builder = dataset.toBuilder();
    builder.setFriendlyName(friendlyName);
    Dataset updatedDataset = builder.build().update();
    // [END update]
    return updatedDataset;
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Builder(com.google.cloud.bigquery.Dataset.Builder)

Example 7 with Dataset

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

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

the class BigQuerySnippets method updateDataset.

/**
   * Example of updating a dataset by changing its friendly name.
   */
// [TARGET update(DatasetInfo, DatasetOption...)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "some_new_friendly_name"]
public Dataset updateDataset(String datasetName, String newFriendlyName) {
    // [START updateDataset]
    Dataset oldDataset = bigquery.getDataset(datasetName);
    DatasetInfo datasetInfo = oldDataset.toBuilder().setFriendlyName(newFriendlyName).build();
    Dataset newDataset = bigquery.update(datasetInfo);
    // [END updateDataset]
    return newDataset;
}
Also used : DatasetInfo(com.google.cloud.bigquery.DatasetInfo) Dataset(com.google.cloud.bigquery.Dataset)

Example 9 with Dataset

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

the class ITDatasetSnippets method testUpdate.

@Test
public void testUpdate() {
    assertNull(dataset.getFriendlyName());
    Dataset updatedDataset = datasetSnippets.updateDataset(FRIENDLY_NAME);
    assertEquals(FRIENDLY_NAME, updatedDataset.getFriendlyName());
}
Also used : Dataset(com.google.cloud.bigquery.Dataset) Test(org.junit.Test)

Example 10 with Dataset

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

the class BigQuerySnippets method createDataset.

/**
   * Example of creating a dataset.
   */
// [TARGET create(DatasetInfo, DatasetOption...)]
// [VARIABLE "my_dataset_name"]
public Dataset createDataset(String datasetName) {
    // [START createDataset]
    Dataset dataset = null;
    DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
    try {
        // the dataset was created
        dataset = bigquery.create(datasetInfo);
    } catch (BigQueryException e) {
    // the dataset was not created
    }
    // [END createDataset]
    return dataset;
}
Also used : DatasetInfo(com.google.cloud.bigquery.DatasetInfo) Dataset(com.google.cloud.bigquery.Dataset) BigQueryException(com.google.cloud.bigquery.BigQueryException)

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