Beispiel #1
0
 @BeforeClass
 public static void beforeClass() throws InterruptedException {
   RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
   RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
   bigquery = bigqueryHelper.options().service();
   storage = gcsHelper.options().service();
   storage.create(BucketInfo.of(BUCKET));
   storage.create(
       BlobInfo.builder(BUCKET, LOAD_FILE).contentType("text/plain").build(),
       CSV_CONTENT.getBytes(StandardCharsets.UTF_8));
   storage.create(
       BlobInfo.builder(BUCKET, JSON_LOAD_FILE).contentType("application/json").build(),
       JSON_CONTENT.getBytes(StandardCharsets.UTF_8));
   DatasetInfo info = DatasetInfo.builder(DATASET).description(DESCRIPTION).build();
   bigquery.create(info);
   LoadJobConfiguration configuration =
       LoadJobConfiguration.builder(
               TABLE_ID, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json())
           .createDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED)
           .schema(TABLE_SCHEMA)
           .build();
   Job job = bigquery.create(JobInfo.of(configuration));
   while (!job.isDone()) {
     Thread.sleep(1000);
   }
   assertNull(job.status().error());
 }
Beispiel #2
0
 @Test
 public void testUpdateDataset() {
   Dataset dataset =
       bigquery.create(DatasetInfo.builder(OTHER_DATASET).description("Some Description").build());
   assertNotNull(dataset);
   assertEquals(bigquery.options().projectId(), dataset.datasetId().project());
   assertEquals(OTHER_DATASET, dataset.datasetId().dataset());
   assertEquals("Some Description", dataset.description());
   Dataset updatedDataset =
       bigquery.update(dataset.toBuilder().description("Updated Description").build());
   assertEquals("Updated Description", updatedDataset.description());
   assertTrue(dataset.delete());
 }
Beispiel #3
0
 @Test
 public void testUpdateDatasetWithSelectedFields() {
   Dataset dataset =
       bigquery.create(DatasetInfo.builder(OTHER_DATASET).description("Some Description").build());
   assertNotNull(dataset);
   assertEquals(bigquery.options().projectId(), dataset.datasetId().project());
   assertEquals(OTHER_DATASET, dataset.datasetId().dataset());
   assertEquals("Some Description", dataset.description());
   Dataset updatedDataset =
       bigquery.update(
           dataset.toBuilder().description("Updated Description").build(),
           DatasetOption.fields(DatasetField.DESCRIPTION));
   assertEquals("Updated Description", updatedDataset.description());
   assertNull(updatedDataset.creationTime());
   assertNull(updatedDataset.defaultTableLifetime());
   assertNull(updatedDataset.acl());
   assertNull(updatedDataset.etag());
   assertNull(updatedDataset.friendlyName());
   assertNull(updatedDataset.id());
   assertNull(updatedDataset.lastModified());
   assertNull(updatedDataset.location());
   assertNull(updatedDataset.selfLink());
   assertTrue(dataset.delete());
 }