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