Search in sources :

Example 1 with RemoteBigQueryHelper

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

Aggregations

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