From ee197556845da4d18d30cef053a4d4e060440c6f Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Fri, 14 Jul 2023 14:19:29 -0400 Subject: [PATCH 01/10] feat: adds Exception handling to handle ALREADy EXISTS error --- .../google/cloud/bigquery/BigQueryImpl.java | 38 +++++++++++++++++-- .../cloud/bigquery/it/ITBigQueryTest.java | 23 +++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index d1bbcb5e2..99b01bf07 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -21,6 +21,7 @@ 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; @@ -55,7 +56,12 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.checkerframework.checker.nullness.qual.NonNull; +import org.threeten.bp.Instant; +import org.threeten.bp.temporal.ChronoUnit; +import org.threeten.extra.Days; final class BigQueryImpl extends BaseService implements BigQuery { @@ -422,15 +428,39 @@ public com.google.api.services.bigquery.model.Job call() { } if (!idRandom) { + if (createException instanceof BigQueryException) { + + GoogleJsonResponseException createExceptionCause = (GoogleJsonResponseException) createException.getCause(); + + Pattern pattern = Pattern.compile(".*Already.*Exists:.*Job.*", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(createExceptionCause.getMessage()); + + if (matcher.find() && createExceptionCause.getStatusCode() == 409) { + // If the Job ALREADY EXISTS, retrieve it. + Job job = this.getJob(jobInfo.getJobId()); + + long jobCreationTime = job.getStatistics().getCreationTime(); + long endTime = System.currentTimeMillis(); + long startTime = Instant.ofEpochMilli(endTime) + .minus(1, ChronoUnit.DAYS) + .toEpochMilli(); + + // Only return the job if it has been created in the past 24 hours. + // This is assuming any job older than 24 hours is a valid duplicate JobID + // and not a false positive like b/290419183 + if(jobCreationTime>=startTime && jobCreationTime<=endTime){ + return job; + } + + } + } throw createException; } // If create RPC fails, it's still possible that the job has been successfully - // created, - // and get might work. + // created, and get might work. // We can only do this if we randomly generated the ID. Otherwise we might - // mistakenly - // fetch a job created by someone else. + // mistakenly fetch a job created by someone else. Job job; try { job = getJob(finalJobId[0]); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index b80fb02df..4264ba009 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -83,6 +83,7 @@ import com.google.cloud.bigquery.InsertAllRequest.RowToInsert; import com.google.cloud.bigquery.InsertAllResponse; import com.google.cloud.bigquery.Job; +import com.google.cloud.bigquery.JobConfiguration; import com.google.cloud.bigquery.JobId; import com.google.cloud.bigquery.JobInfo; import com.google.cloud.bigquery.JobStatistics; @@ -6076,4 +6077,26 @@ public void testForeignKeysUpdate() { bigquery.delete(tableIdPk2); } } + + @Test + public void testAlreadyExistJobExceptionHandling() throws InterruptedException { + String query = "SELECT TimestampField, StringField, BooleanField FROM " + 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. + try { + bigquery.query(QueryJobConfiguration.newBuilder(query).build(), jobId); + // Test succeeds if Exception is not thrown and code flow reaches this statement. + assertTrue(true); + }catch (BigQueryException ex){ + // test fails if an exception is thrown + assertTrue(false); + } + + } } From f5626255909a08a1d10533e6b9c46421bc26763c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 14 Jul 2023 18:22:14 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/bigquery/BigQueryImpl.java | 11 ++++------- .../com/google/cloud/bigquery/it/ITBigQueryTest.java | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 99b01bf07..a1de28085 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -61,7 +61,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.threeten.bp.Instant; import org.threeten.bp.temporal.ChronoUnit; -import org.threeten.extra.Days; final class BigQueryImpl extends BaseService implements BigQuery { @@ -430,7 +429,8 @@ public com.google.api.services.bigquery.model.Job call() { if (!idRandom) { if (createException instanceof BigQueryException) { - 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()); @@ -441,17 +441,14 @@ public com.google.api.services.bigquery.model.Job call() { long jobCreationTime = job.getStatistics().getCreationTime(); long endTime = System.currentTimeMillis(); - long startTime = Instant.ofEpochMilli(endTime) - .minus(1, ChronoUnit.DAYS) - .toEpochMilli(); + long startTime = Instant.ofEpochMilli(endTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID // and not a false positive like b/290419183 - if(jobCreationTime>=startTime && jobCreationTime<=endTime){ + if (jobCreationTime >= startTime && jobCreationTime <= endTime) { return job; } - } } throw createException; diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 4264ba009..d17ee1e55 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6081,7 +6081,7 @@ public void testForeignKeysUpdate() { @Test public void testAlreadyExistJobExceptionHandling() throws InterruptedException { String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); - JobId jobId =JobId.newBuilder().setRandomJob().build(); + JobId jobId = JobId.newBuilder().setRandomJob().build(); JobConfiguration queryJobConfiguration = QueryJobConfiguration.newBuilder(query).build(); // Creating the job with the explicit jobID @@ -6093,10 +6093,9 @@ public void testAlreadyExistJobExceptionHandling() throws InterruptedException { bigquery.query(QueryJobConfiguration.newBuilder(query).build(), jobId); // Test succeeds if Exception is not thrown and code flow reaches this statement. assertTrue(true); - }catch (BigQueryException ex){ + } catch (BigQueryException ex) { // test fails if an exception is thrown assertTrue(false); } - } } From 5f70864377aa733a36ebd2702d4fa67e74fd8007 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 14 Jul 2023 18:22:15 +0000 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/bigquery/BigQueryImpl.java | 11 ++++------- .../com/google/cloud/bigquery/it/ITBigQueryTest.java | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 99b01bf07..a1de28085 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -61,7 +61,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.threeten.bp.Instant; import org.threeten.bp.temporal.ChronoUnit; -import org.threeten.extra.Days; final class BigQueryImpl extends BaseService implements BigQuery { @@ -430,7 +429,8 @@ public com.google.api.services.bigquery.model.Job call() { if (!idRandom) { if (createException instanceof BigQueryException) { - 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()); @@ -441,17 +441,14 @@ public com.google.api.services.bigquery.model.Job call() { long jobCreationTime = job.getStatistics().getCreationTime(); long endTime = System.currentTimeMillis(); - long startTime = Instant.ofEpochMilli(endTime) - .minus(1, ChronoUnit.DAYS) - .toEpochMilli(); + long startTime = Instant.ofEpochMilli(endTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID // and not a false positive like b/290419183 - if(jobCreationTime>=startTime && jobCreationTime<=endTime){ + if (jobCreationTime >= startTime && jobCreationTime <= endTime) { return job; } - } } throw createException; diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 4264ba009..d17ee1e55 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6081,7 +6081,7 @@ public void testForeignKeysUpdate() { @Test public void testAlreadyExistJobExceptionHandling() throws InterruptedException { String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); - JobId jobId =JobId.newBuilder().setRandomJob().build(); + JobId jobId = JobId.newBuilder().setRandomJob().build(); JobConfiguration queryJobConfiguration = QueryJobConfiguration.newBuilder(query).build(); // Creating the job with the explicit jobID @@ -6093,10 +6093,9 @@ public void testAlreadyExistJobExceptionHandling() throws InterruptedException { bigquery.query(QueryJobConfiguration.newBuilder(query).build(), jobId); // Test succeeds if Exception is not thrown and code flow reaches this statement. assertTrue(true); - }catch (BigQueryException ex){ + } catch (BigQueryException ex) { // test fails if an exception is thrown assertTrue(false); } - } } From 9197bdf5588f0243e2cc20e0e9f028d82fedfda7 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Mon, 17 Jul 2023 14:39:40 -0400 Subject: [PATCH 04/10] chore: add more conditions --- .../java/com/google/cloud/bigquery/BigQueryImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index a1de28085..db27fc562 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -427,7 +427,9 @@ public com.google.api.services.bigquery.model.Job call() { } if (!idRandom) { - if (createException instanceof BigQueryException) { + if (createException instanceof BigQueryException && + createException.getCause() != null && + createException.getCause() instanceof GoogleJsonResponseException) { GoogleJsonResponseException createExceptionCause = (GoogleJsonResponseException) createException.getCause(); @@ -446,7 +448,12 @@ public com.google.api.services.bigquery.model.Job call() { // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID // and not a false positive like b/290419183 +<<<<<<< Updated upstream if (jobCreationTime >= startTime && jobCreationTime <= endTime) { +======= + if(jobCreationTime>=startTime && jobCreationTime<=endTime){ + +>>>>>>> Stashed changes return job; } } From 24c76379b99445db3eae549e2be2a1244c6cb7d2 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Mon, 17 Jul 2023 14:44:56 -0400 Subject: [PATCH 05/10] chore: format --- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index db27fc562..e51a287e0 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -448,12 +448,7 @@ public com.google.api.services.bigquery.model.Job call() { // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID // and not a false positive like b/290419183 -<<<<<<< Updated upstream if (jobCreationTime >= startTime && jobCreationTime <= endTime) { -======= - if(jobCreationTime>=startTime && jobCreationTime<=endTime){ - ->>>>>>> Stashed changes return job; } } From 109bb59c67b5b16ab480fbf75ae45633db227d53 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 17 Jul 2023 18:46:50 +0000 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 +++--- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 707158574..1f7d1540d 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ implementation 'com.google.cloud:google-cloud-bigquery' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.29.0' +implementation 'com.google.cloud:google-cloud-bigquery:2.30.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.29.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.30.0" ``` @@ -351,7 +351,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.29.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.30.0 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index e51a287e0..a48eddad1 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -427,9 +427,9 @@ 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 + && createException.getCause() instanceof GoogleJsonResponseException) { GoogleJsonResponseException createExceptionCause = (GoogleJsonResponseException) createException.getCause(); From 054f6f3d94b37b820af1197d865cd0a79c7bc13b Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Mon, 17 Jul 2023 16:05:50 -0400 Subject: [PATCH 07/10] chore: don't ad extra dependency --- .../com/google/cloud/bigquery/BigQueryImpl.java | 14 ++++++-------- .../google/cloud/bigquery/it/ITBigQueryTest.java | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index a48eddad1..b1a689dbb 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -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; @@ -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()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index d17ee1e55..9448e01e8 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6080,7 +6080,7 @@ 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(); @@ -6088,7 +6088,7 @@ public void testAlreadyExistJobExceptionHandling() throws InterruptedException { 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. From 8d2005b110bc99155adad196455b074161c5c0a3 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 17 Jul 2023 20:08:19 +0000 Subject: [PATCH 08/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 7 +++---- .../java/com/google/cloud/bigquery/it/ITBigQueryTest.java | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index b1a689dbb..3e218307d 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -426,16 +426,15 @@ public com.google.api.services.bigquery.model.Job call() { } if (!idRandom) { - if (createException instanceof BigQueryException && - createException.getCause() != null ) { + if (createException instanceof BigQueryException && createException.getCause() != null) { /*GoogleJsonResponseException createExceptionCause = - (GoogleJsonResponseException) createException.getCause();*/ + (GoogleJsonResponseException) createException.getCause();*/ Pattern pattern = Pattern.compile(".*Already.*Exists:.*Job.*", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(createException.getCause().getMessage()); - if (matcher.find() ) { + if (matcher.find()) { // If the Job ALREADY EXISTS, retrieve it. Job job = this.getJob(jobInfo.getJobId()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 9448e01e8..085dd57e7 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6080,7 +6080,11 @@ public void testForeignKeysUpdate() { @Test public void testAlreadyExistJobExceptionHandling() throws InterruptedException { - String query = "SELECT TimestampField, StringField, BooleanField FROM " +DATASET + "."+ 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(); From 25b58f0dac25106e9574a2aadfd829660f50b061 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Fri, 21 Jul 2023 15:36:16 -0400 Subject: [PATCH 09/10] nit --- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 6 +++--- .../java/com/google/cloud/bigquery/it/ITBigQueryTest.java | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 3e218307d..d3aff816a 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -439,13 +439,13 @@ public com.google.api.services.bigquery.model.Job call() { Job job = this.getJob(jobInfo.getJobId()); long jobCreationTime = job.getStatistics().getCreationTime(); - long endTime = System.currentTimeMillis(); - long startTime = Instant.ofEpochMilli(endTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); + long jobMinStaleTime = System.currentTimeMillis(); + long jobMaxStaleTime = Instant.ofEpochMilli(jobMinStaleTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID // and not a false positive like b/290419183 - if (jobCreationTime >= startTime && jobCreationTime <= endTime) { + if (jobCreationTime >= jobMaxStaleTime && jobCreationTime <= jobMinStaleTime) { return job; } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 085dd57e7..1e0db620b 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6099,7 +6099,9 @@ public void testAlreadyExistJobExceptionHandling() throws InterruptedException { assertTrue(true); } catch (BigQueryException ex) { // test fails if an exception is thrown - assertTrue(false); + if(ex.getCause()!= null && ex.getCause().getMessage().contains("Already Exists: Job")){ + fail("Already exists error should not be thrown"); + } } } } From 67c1f08ba4e3b911ec8e13858371a378b3c6c722 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 21 Jul 2023 19:38:46 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++++---- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 3 ++- .../java/com/google/cloud/bigquery/it/ITBigQueryTest.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1f7d1540d..3d433fab2 100644 --- a/README.md +++ b/README.md @@ -53,20 +53,20 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.18.0') +implementation platform('com.google.cloud:libraries-bom:26.19.0') implementation 'com.google.cloud:google-cloud-bigquery' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.30.0' +implementation 'com.google.cloud:google-cloud-bigquery:2.30.1' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.30.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.30.1" ``` @@ -351,7 +351,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.30.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.30.1 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index d3aff816a..ef7e8cb8b 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -440,7 +440,8 @@ public com.google.api.services.bigquery.model.Job call() { long jobCreationTime = job.getStatistics().getCreationTime(); long jobMinStaleTime = System.currentTimeMillis(); - long jobMaxStaleTime = Instant.ofEpochMilli(jobMinStaleTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); + long jobMaxStaleTime = + Instant.ofEpochMilli(jobMinStaleTime).minus(1, ChronoUnit.DAYS).toEpochMilli(); // Only return the job if it has been created in the past 24 hours. // This is assuming any job older than 24 hours is a valid duplicate JobID diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 1e0db620b..07942b11a 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -6099,7 +6099,7 @@ public void testAlreadyExistJobExceptionHandling() throws InterruptedException { assertTrue(true); } catch (BigQueryException ex) { // test fails if an exception is thrown - if(ex.getCause()!= null && ex.getCause().getMessage().contains("Already Exists: Job")){ + if (ex.getCause() != null && ex.getCause().getMessage().contains("Already Exists: Job")) { fail("Already exists error should not be thrown"); } }