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());
}
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;
}
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());
}
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;
}
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());
}
Aggregations