Search in sources :

Example 1 with DatasetInfo

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

the class ITBigQueryTest method beforeClass.

@BeforeClass
public static void beforeClass() throws InterruptedException, TimeoutException {
    RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
    RemoteStorageHelper storageHelper = RemoteStorageHelper.create();
    bigquery = bigqueryHelper.getOptions().getService();
    storage = storageHelper.getOptions().getService();
    storage.create(BucketInfo.of(BUCKET));
    storage.create(BlobInfo.newBuilder(BUCKET, LOAD_FILE).setContentType("text/plain").build(), CSV_CONTENT.getBytes(StandardCharsets.UTF_8));
    storage.create(BlobInfo.newBuilder(BUCKET, JSON_LOAD_FILE).setContentType("application/json").build(), JSON_CONTENT.getBytes(StandardCharsets.UTF_8));
    DatasetInfo info = DatasetInfo.newBuilder(DATASET).setDescription(DESCRIPTION).setLabels(LABELS).build();
    bigquery.create(info);
    LoadJobConfiguration configuration = LoadJobConfiguration.newBuilder(TABLE_ID, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()).setCreateDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED).setSchema(TABLE_SCHEMA).build();
    Job job = bigquery.create(JobInfo.of(configuration));
    job = job.waitFor();
    assertNull(job.getStatus().getError());
}
Also used : DatasetInfo(com.google.cloud.bigquery.DatasetInfo) RemoteStorageHelper(com.google.cloud.storage.testing.RemoteStorageHelper) RemoteBigQueryHelper(com.google.cloud.bigquery.testing.RemoteBigQueryHelper) LoadJobConfiguration(com.google.cloud.bigquery.LoadJobConfiguration) Job(com.google.cloud.bigquery.Job) BeforeClass(org.junit.BeforeClass)

Example 2 with DatasetInfo

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

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

the class ITDatasetSnippets method testDelete.

@Test
public void testDelete() {
    String datasetName = RemoteBigQueryHelper.generateDatasetName();
    DatasetInfo dataset = DatasetInfo.newBuilder(datasetName).build();
    DatasetSnippets datasetSnippets = new DatasetSnippets(bigquery.create(dataset));
    assertTrue(datasetSnippets.deleteDataset());
}
Also used : DatasetInfo(com.google.cloud.bigquery.DatasetInfo) Test(org.junit.Test)

Example 4 with DatasetInfo

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

Example 5 with DatasetInfo

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

the class QuickstartSample method main.

public static void main(String... args) throws Exception {
    // Instantiate a client. If you don't specify credentials when constructing a client, the
    // client library will look for credentials in the environment, such as the
    // GOOGLE_APPLICATION_CREDENTIALS environment variable.
    BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
    // The name for the new dataset
    String datasetName = "my_new_dataset";
    // Prepares a new dataset
    Dataset dataset = null;
    DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
    // Creates the dataset
    dataset = bigquery.create(datasetInfo);
    System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset());
}
Also used : BigQuery(com.google.cloud.bigquery.BigQuery) DatasetInfo(com.google.cloud.bigquery.DatasetInfo) Dataset(com.google.cloud.bigquery.Dataset)

Aggregations

DatasetInfo (com.google.cloud.bigquery.DatasetInfo)5 Dataset (com.google.cloud.bigquery.Dataset)3 BigQuery (com.google.cloud.bigquery.BigQuery)1 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 Job (com.google.cloud.bigquery.Job)1 LoadJobConfiguration (com.google.cloud.bigquery.LoadJobConfiguration)1 RemoteBigQueryHelper (com.google.cloud.bigquery.testing.RemoteBigQueryHelper)1 RemoteStorageHelper (com.google.cloud.storage.testing.RemoteStorageHelper)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1