use of com.google.cloud.bigquery.BigQueryException in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testUpdateNonExistingTable.
@Test
public void testUpdateNonExistingTable() {
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, "test_update_non_existing_table"), StandardTableDefinition.of(SIMPLE_SCHEMA));
try {
bigquery.update(tableInfo);
fail("BigQueryException was expected");
} catch (BigQueryException e) {
BigQueryError error = e.getError();
assertNotNull(error);
assertEquals("notFound", error.getReason());
assertNotNull(error.getMessage());
}
}
use of com.google.cloud.bigquery.BigQueryException in project google-cloud-java by GoogleCloudPlatform.
the class HttpBigQueryRpc method write.
@Override
public Job write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last) {
try {
GenericUrl url = new GenericUrl(uploadId);
HttpRequest httpRequest = bigquery.getRequestFactory().buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length));
httpRequest.setParser(bigquery.getObjectParser());
long limit = destOffset + length;
StringBuilder range = new StringBuilder("bytes ");
range.append(destOffset).append('-').append(limit - 1).append('/');
if (last) {
range.append(limit);
} else {
range.append('*');
}
httpRequest.getHeaders().setContentRange(range.toString());
int code;
String message;
IOException exception = null;
HttpResponse response = null;
try {
response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
exception = ex;
code = ex.getStatusCode();
message = ex.getStatusMessage();
}
if (!last && code != HTTP_RESUME_INCOMPLETE || last && !(code == HTTP_OK || code == HTTP_CREATED)) {
if (exception != null) {
throw exception;
}
throw new BigQueryException(code, message);
}
return last && response != null ? response.parseAs(Job.class) : null;
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.cloud.bigquery.BigQueryException in project google-cloud-java by GoogleCloudPlatform.
the class BigQuerySnippets method createJob.
/**
* Example of creating a query job.
*/
// [TARGET create(JobInfo, JobOption...)]
// [VARIABLE "SELECT field FROM my_dataset_name.my_table_name"]
public Job createJob(String query) {
// [START createJob]
Job job = null;
JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
JobInfo jobInfo = JobInfo.of(jobConfiguration);
try {
job = bigquery.create(jobInfo);
} catch (BigQueryException e) {
// the job was not created
}
// [END createJob]
return job;
}
use of com.google.cloud.bigquery.BigQueryException 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.BigQueryException in project workbench by all-of-us.
the class CohortReviewController method createParticipantCohortStatusesList.
/**
* Helper method that builds a list of {@link ParticipantCohortStatus} from BigQuery results.
*
* @param cohortReviewId
* @param result
* @param rm
* @return
*/
private List<ParticipantCohortStatus> createParticipantCohortStatusesList(Long cohortReviewId, QueryResult result, Map<String, Integer> rm) {
List<ParticipantCohortStatus> participantCohortStatuses = new ArrayList<>();
for (List<FieldValue> row : result.iterateAll()) {
String birthDateTimeString = bigQueryService.getString(row, rm.get("birth_datetime"));
if (birthDateTimeString == null) {
throw new BigQueryException(500, "birth_datetime is null at position: " + rm.get("birth_datetime"));
}
java.util.Date birthDate = Date.from(Instant.ofEpochMilli(Double.valueOf(birthDateTimeString).longValue() * 1000));
participantCohortStatuses.add(new ParticipantCohortStatus().participantKey(new ParticipantCohortStatusKey(cohortReviewId, bigQueryService.getLong(row, rm.get("person_id")))).status(CohortStatus.NOT_REVIEWED).birthDate(new java.sql.Date(birthDate.getTime())).genderConceptId(bigQueryService.getLong(row, rm.get("gender_concept_id"))).raceConceptId(bigQueryService.getLong(row, rm.get("race_concept_id"))).ethnicityConceptId(bigQueryService.getLong(row, rm.get("ethnicity_concept_id"))));
}
return participantCohortStatuses;
}
Aggregations