use of com.google.cloud.bigquery.Job in project google-cloud-java by GoogleCloudPlatform.
the class ITJobSnippets method testIsDone.
@Test
public void testIsDone() throws Exception {
JobConfiguration jobConfig = QueryJobConfiguration.newBuilder(QUERY).setUseLegacySql(false).build();
JobInfo jobInfo = JobInfo.newBuilder(jobConfig).build();
Job job = bigquery.create(jobInfo);
JobSnippets jobSnippets = new JobSnippets(job);
jobSnippets.isDone();
assertTrue(job.isDone());
}
use of com.google.cloud.bigquery.Job in project google-cloud-java by GoogleCloudPlatform.
the class ITTableSnippets method testExtractAndLoadSingle.
@Test
public void testExtractAndLoadSingle() {
String gcsFile = "gs://" + BUCKET_NAME + "/extractTest.csv";
Job extractJob = tableSnippets.extractSingle("CSV", gcsFile);
assertSuccessful(extractJob);
Job loadJob = tableSnippets.loadSingle(gcsFile);
assertSuccessful(loadJob);
}
use of com.google.cloud.bigquery.Job in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateAndGetJob.
@Test
public void testCreateAndGetJob() throws InterruptedException, TimeoutException {
String sourceTableName = "test_create_and_get_job_source_table";
String destinationTableName = "test_create_and_get_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(sourceTableName, createdTable.getTableId().getTable());
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration copyJobConfiguration = CopyJobConfiguration.of(destinationTable, sourceTable);
Job createdJob = bigquery.create(JobInfo.of(copyJobConfiguration));
Job remoteJob = bigquery.getJob(createdJob.getJobId());
assertEquals(createdJob.getJobId(), remoteJob.getJobId());
CopyJobConfiguration createdConfiguration = createdJob.getConfiguration();
CopyJobConfiguration remoteConfiguration = remoteJob.getConfiguration();
assertEquals(createdConfiguration.getSourceTables(), remoteConfiguration.getSourceTables());
assertEquals(createdConfiguration.getDestinationTable(), remoteConfiguration.getDestinationTable());
assertEquals(createdConfiguration.getCreateDisposition(), remoteConfiguration.getCreateDisposition());
assertEquals(createdConfiguration.getWriteDisposition(), remoteConfiguration.getWriteDisposition());
assertNotNull(remoteJob.getEtag());
assertNotNull(remoteJob.getStatistics());
assertNotNull(remoteJob.getStatus());
assertEquals(createdJob.getSelfLink(), remoteJob.getSelfLink());
assertEquals(createdJob.getUserEmail(), remoteJob.getUserEmail());
assertTrue(createdTable.delete());
Job completedJob = remoteJob.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS), WaitForOption.timeout(1, TimeUnit.MINUTES));
assertNotNull(completedJob);
assertNull(completedJob.getStatus().getError());
assertTrue(bigquery.delete(DATASET, destinationTableName));
}
use of com.google.cloud.bigquery.Job 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.Job in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testListJobs.
@Test
public void testListJobs() {
Page<Job> jobs = bigquery.listJobs();
for (Job job : jobs.getValues()) {
assertNotNull(job.getJobId());
assertNotNull(job.getStatistics());
assertNotNull(job.getStatus());
assertNotNull(job.getUserEmail());
assertNotNull(job.getGeneratedId());
}
}
Aggregations