Skip to content

Commit

Permalink
chore: don't ad extra dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Neenu1995 committed Jul 17, 2023
1 parent 109bb59 commit 054f6f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;

import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.paging.Page;
Expand Down Expand Up @@ -427,17 +426,16 @@ public com.google.api.services.bigquery.model.Job call() {
}

if (!idRandom) {
if (createException instanceof BigQueryException
&& createException.getCause() != null
&& createException.getCause() instanceof GoogleJsonResponseException) {
if (createException instanceof BigQueryException &&
createException.getCause() != null ) {

GoogleJsonResponseException createExceptionCause =
(GoogleJsonResponseException) createException.getCause();
/*GoogleJsonResponseException createExceptionCause =
(GoogleJsonResponseException) createException.getCause();*/

Pattern pattern = Pattern.compile(".*Already.*Exists:.*Job.*", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(createExceptionCause.getMessage());
Matcher matcher = pattern.matcher(createException.getCause().getMessage());

if (matcher.find() && createExceptionCause.getStatusCode() == 409) {
if (matcher.find() ) {
// If the Job ALREADY EXISTS, retrieve it.
Job job = this.getJob(jobInfo.getJobId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6080,15 +6080,15 @@ public void testForeignKeysUpdate() {

@Test
public void testAlreadyExistJobExceptionHandling() throws InterruptedException {
String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable();
String query = "SELECT TimestampField, StringField, BooleanField FROM " +DATASET + "."+ TABLE_ID.getTable();
JobId jobId = JobId.newBuilder().setRandomJob().build();

JobConfiguration queryJobConfiguration = QueryJobConfiguration.newBuilder(query).build();
// Creating the job with the explicit jobID
bigquery.create(JobInfo.of(jobId, queryJobConfiguration));
// Calling the query method with the job that has already been created.
// This should throw ALREADY_EXISTS error without the exception handling added
// or if the job id older than 24 hours.
// or if the job is older than 24 hours.
try {
bigquery.query(QueryJobConfiguration.newBuilder(query).build(), jobId);
// Test succeeds if Exception is not thrown and code flow reaches this statement.
Expand Down

0 comments on commit 054f6f3

Please sign in to comment.