diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index fd19c5541f..3d2f828246 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:0ab8611cd29e7aba8413c6f83ed1734b60fddf845b4a37808b742302d32dd043 + digest: sha256:a4d7b2cfc6a9d6b378a6b2458740eae15fcab28854bd23dad3a15102d2e47c87 diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 583a840c4d..960ae2ba05 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -16,6 +16,7 @@ branchProtectionRules: - units (11) - 'Kokoro - Test: Integration' - cla/google + - OwlBot Post Processor - pattern: 1.127.12-sp isAdminEnforced: true requiredApprovingReviewCount: 1 @@ -60,6 +61,7 @@ branchProtectionRules: - units (11) - 'Kokoro - Test: Integration' - cla/google + - OwlBot Post Processor permissionRules: - team: api-bigquery permission: admin diff --git a/.kokoro/build.sh b/.kokoro/build.sh index e490e6cd70..d01df07d4b 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -71,7 +71,7 @@ integration) ;; graalvm) # Run Unit and Integration Tests with Native Image - mvn test -Pnative -Penable-integration-tests + mvn -ntp -Pnative -Penable-integration-tests test RETURN_CODE=$? ;; samples) diff --git a/.repo-metadata.json b/.repo-metadata.json index 1305be96ff..7ca892467f 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -12,5 +12,6 @@ "distribution_name": "com.google.cloud:google-cloud-bigquery", "codeowner_team": "@googleapis/api-bigquery", "api_id": "bigquery.googleapis.com", + "library_type": "REST", "requires_billing": true } diff --git a/CHANGELOG.md b/CHANGELOG.md index 3afff959c2..2aef61767a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## [2.6.0](https://www.github.com/googleapis/java-bigquery/compare/v2.5.1...v2.6.0) (2021-12-27) + + +### Features + +* create Job retry for rate limit exceeded with status code 200 ([#1744](https://www.github.com/googleapis/java-bigquery/issues/1744)) ([97a61dc](https://www.github.com/googleapis/java-bigquery/commit/97a61dc90fb701986a51a12c9c83b7138894307a)) + + +### Bug Fixes + +* **java:** add -ntp flag to native image testing command ([#1299](https://www.github.com/googleapis/java-bigquery/issues/1299)) ([#1738](https://www.github.com/googleapis/java-bigquery/issues/1738)) ([585875e](https://www.github.com/googleapis/java-bigquery/commit/585875e776e17660c58f9f8fe8385f13833bca57)) + + +### Documentation + +* rename alter materialized view to update ([#1754](https://www.github.com/googleapis/java-bigquery/issues/1754)) ([0b7d911](https://www.github.com/googleapis/java-bigquery/commit/0b7d91135222505f0eb01e8b40095156a073b62e)) +* **samples:** update UpdateTableExpirationIT to fix failing IT. ([#1753](https://www.github.com/googleapis/java-bigquery/issues/1753)) ([a62a9f4](https://www.github.com/googleapis/java-bigquery/commit/a62a9f4fdda465b8c9e2f67f111d1b1b4a067903)) + + +### Dependencies + +* update dependency com.google.apis:google-api-services-bigquery to v2-rev20211129-1.32.1 ([#1737](https://www.github.com/googleapis/java-bigquery/issues/1737)) ([776ff10](https://www.github.com/googleapis/java-bigquery/commit/776ff1004592f62799ff0244a448d6911bcca5be)) +* update dependency com.google.cloud:google-cloud-bigtable to v2.3.1 ([#1741](https://www.github.com/googleapis/java-bigquery/issues/1741)) ([2f31a0a](https://www.github.com/googleapis/java-bigquery/commit/2f31a0a4f491eca25cbd3992e48f94214bfd605b)) +* update dependency com.google.cloud:google-cloud-bigtable to v2.4.0 ([#1746](https://www.github.com/googleapis/java-bigquery/issues/1746)) ([92e5d02](https://www.github.com/googleapis/java-bigquery/commit/92e5d02ff25511233b15f07844bb8b13de2dc72f)) +* update dependency com.google.cloud:google-cloud-storage to v2.2.2 ([#1740](https://www.github.com/googleapis/java-bigquery/issues/1740)) ([2022301](https://www.github.com/googleapis/java-bigquery/commit/2022301b39390f20796b8c5b3d6ee0e82aa127aa)) +* update jmh.version to v1.34 ([#1758](https://www.github.com/googleapis/java-bigquery/issues/1758)) ([5a2bcbc](https://www.github.com/googleapis/java-bigquery/commit/5a2bcbc7197fa75a464ed62d3e3df3bd43652b9d)) + ### [2.5.1](https://www.github.com/googleapis/java-bigquery/compare/v2.5.0...v2.5.1) (2021-12-03) diff --git a/README.md b/README.md index 5be608437b..3f53801cee 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google com.google.cloud libraries-bom - 24.0.0 + 24.1.1 pom import @@ -33,6 +33,7 @@ See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google com.google.cloud google-cloud-bigquery + ``` @@ -43,7 +44,7 @@ If you are using Maven without BOM, add this to your dependencies: com.google.cloud google-cloud-bigquery - 2.5.0 + 2.5.1 ``` @@ -51,20 +52,20 @@ If you are using Maven without 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:24.0.0') +implementation platform('com.google.cloud:libraries-bom:24.1.1') 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.5.0' +implementation 'com.google.cloud:google-cloud-bigquery:2.5.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.5.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.5.1" ``` ## Authentication @@ -112,7 +113,6 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-bigquery/tree | --------------------------- | --------------------------------- | ------ | | Add Column Load Append | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AddColumnLoadAppend.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AddColumnLoadAppend.java) | | Add Empty Column | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AddEmptyColumn.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AddEmptyColumn.java) | -| Alter Materialized View | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AlterMaterializedView.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AlterMaterializedView.java) | | Auth Drive Scope | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AuthDriveScope.java) | | Auth Snippets | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AuthSnippets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AuthSnippets.java) | | Auth User Flow | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/AuthUserFlow.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/AuthUserFlow.java) | @@ -234,6 +234,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-bigquery/tree | Update Dataset Expiration | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetExpiration.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetExpiration.java) | | Update Dataset Partition Expiration | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetPartitionExpiration.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetPartitionExpiration.java) | | Update Iam Policy | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateIamPolicy.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateIamPolicy.java) | +| Update Materialized View | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateMaterializedView.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateMaterializedView.java) | | Update Model Description | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateModelDescription.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateModelDescription.java) | | Update Routine | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateRoutine.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateRoutine.java) | | Update Table Cmek | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/UpdateTableCmek.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateTableCmek.java) | diff --git a/benchmark/pom.xml b/benchmark/pom.xml index 11702beed6..aff3a530e6 100644 --- a/benchmark/pom.xml +++ b/benchmark/pom.xml @@ -6,12 +6,12 @@ google-cloud-bigquery-parent com.google.cloud - 2.5.1 + 2.6.0 UTF-8 - 1.33 + 1.34 benchmark diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index 5e4fd42fb5..62bd66425c 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-bigquery - 2.5.1 + 2.6.0 jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,7 +11,7 @@ com.google.cloud google-cloud-bigquery-parent - 2.5.1 + 2.6.0 google-cloud-bigquery @@ -29,14 +29,6 @@ com.google.http-client google-http-client-jackson2 - - com.google.cloud - google-cloud-datacatalog - - - com.google.api.grpc - proto-google-cloud-datacatalog-v1 - com.google.cloud google-cloud-storage @@ -116,6 +108,16 @@ assertj-core test + + com.google.cloud + google-cloud-datacatalog + test + + + com.google.api.grpc + proto-google-cloud-datacatalog-v1 + test + 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 7d0e4c5550..16814e99a3 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 @@ -347,15 +347,9 @@ public JobId get() { @InternalApi("visible for testing") Job create(JobInfo jobInfo, Supplier idProvider, JobOption... options) { - boolean idRandom = false; - if (jobInfo.getJobId() == null) { - jobInfo = jobInfo.toBuilder().setJobId(idProvider.get()).build(); - idRandom = true; - } - final com.google.api.services.bigquery.model.Job jobPb = - jobInfo.setProjectId(getOptions().getProjectId()).toPb(); - final Map optionsMap = optionMap(options); + final boolean idRandom = (jobInfo.getJobId() == null); + final Map optionsMap = optionMap(options); BigQueryException createException; // NOTE(pongad): This double-try structure is admittedly odd. // translateAndThrow itself throws, and pretends to return an exception only @@ -363,21 +357,36 @@ Job create(JobInfo jobInfo, Supplier idProvider, JobOption... options) { // This makes it difficult to translate without throwing. // Fixing this entails some work on BaseServiceException.translate. // Since that affects a bunch of APIs, we should fix this as a separate change. + final JobId[] finalJobId = new JobId[1]; try { try { return Job.fromPb( this, - runWithRetries( + BigQueryRetryHelper.runWithRetries( new Callable() { @Override public com.google.api.services.bigquery.model.Job call() { - return bigQueryRpc.create(jobPb, optionsMap); + if (idRandom) { + // re-generate a new random job with the same jobInfo when jobId is not + // provided by the user + JobInfo recreatedJobInfo = + jobInfo.toBuilder().setJobId(idProvider.get()).build(); + com.google.api.services.bigquery.model.Job newJobPb = + recreatedJobInfo.setProjectId(getOptions().getProjectId()).toPb(); + finalJobId[0] = recreatedJobInfo.getJobId(); + return bigQueryRpc.create(newJobPb, optionsMap); + } else { + com.google.api.services.bigquery.model.Job jobPb = + jobInfo.setProjectId(getOptions().getProjectId()).toPb(); + return bigQueryRpc.create(jobPb, optionsMap); + } } }, getOptions().getRetrySettings(), - BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER, - getOptions().getClock())); - } catch (RetryHelper.RetryHelperException e) { + EXCEPTION_HANDLER, + getOptions().getClock(), + DEFAULT_RETRY_CONFIG)); + } catch (BigQueryRetryHelper.BigQueryRetryHelperException e) { throw BigQueryException.translateAndThrow(e); } } catch (BigQueryException e) { @@ -396,7 +405,7 @@ public com.google.api.services.bigquery.model.Job call() { // fetch a job created by someone else. Job job; try { - job = getJob(jobInfo.getJobId()); + job = getJob(finalJobId[0]); } catch (BigQueryException e) { throw createException; } diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java index a4e642191c..af472430fc 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java @@ -72,7 +72,8 @@ public boolean shouldRetry( // the exception messages boolean shouldRetry = (shouldRetryBasedOnResult(context, previousThrowable, previousResponse) - || shouldRetryBasedOnBigQueryRetryConfig(previousThrowable, bigQueryRetryConfig)) + || shouldRetryBasedOnBigQueryRetryConfig( + previousThrowable, bigQueryRetryConfig, previousResponse)) && shouldRetryBasedOnTiming(context, nextAttemptSettings); if (LOG.isLoggable(Level.FINEST)) { @@ -92,13 +93,26 @@ public boolean shouldRetry( } private boolean shouldRetryBasedOnBigQueryRetryConfig( - Throwable previousThrowable, BigQueryRetryConfig bigQueryRetryConfig) { + Throwable previousThrowable, + BigQueryRetryConfig bigQueryRetryConfig, + ResponseT previousResponse) { /* We are deciding if a given error should be retried on the basis of error message. Cannot rely on Error/Status code as for example error code 400 (which is not retriable) could be thrown due to rateLimitExceed, which is retriable */ - String errorDesc; - if (previousThrowable != null && (errorDesc = previousThrowable.getMessage()) != null) { + String errorDesc = null; + if (previousThrowable != null) { + errorDesc = previousThrowable.getMessage(); + } else if (previousResponse != null) { + /* + In some cases error messages may come without an exception + e.g. status code 200 with a rate limit exceeded for job create + in these cases there is now previousThrowable so we need to check previousResponse + */ + errorDesc = previousResponse.toString(); + } + + if (errorDesc != null) { errorDesc = errorDesc.toLowerCase(); // for case insensitive comparison for (Iterator retriableMessages = bigQueryRetryConfig.getRetriableErrorMessages().iterator(); @@ -161,7 +175,8 @@ public TimedAttemptSettings createNextAttempt( if (!((shouldRetryBasedOnResult(context, previousThrowable, previousResponse) || shouldRetryBasedOnBigQueryRetryConfig( previousThrowable, - bigQueryRetryConfig)))) { // Calling shouldRetryBasedOnBigQueryRetryConfig to check if + bigQueryRetryConfig, + previousResponse)))) { // Calling shouldRetryBasedOnBigQueryRetryConfig to check if // the error message could be retried return null; } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index 760c84f32a..b00d4b8607 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -1529,6 +1529,30 @@ public void testCreateJobSuccess() { verify(bigqueryRpcMock).create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)); } + @Test + public void testCreateJobFailureShouldRetry() { + when(bigqueryRpcMock.create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS))) + .thenThrow(new BigQueryException(500, "InternalError")) + .thenThrow(new BigQueryException(502, "Bad Gateway")) + .thenThrow(new BigQueryException(503, "Service Unavailable")) + .thenThrow( + new BigQueryException( + 400, RATE_LIMIT_ERROR_MSG)) // retrial on based on RATE_LIMIT_EXCEEDED_MSG + .thenThrow(new BigQueryException(200, RATE_LIMIT_ERROR_MSG)) + .thenReturn(newJobPb()); + + bigquery = options.getService(); + bigquery = + options + .toBuilder() + .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) + .build() + .getService(); + + ((BigQueryImpl) bigquery).create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY)); + verify(bigqueryRpcMock, times(6)).create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)); + } + @Test public void testCreateJobWithSelectedFields() { when(bigqueryRpcMock.create( diff --git a/pom.xml b/pom.xml index 267afdb5c7..8a7dd43003 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 2.5.1 + 2.6.0 BigQuery Parent https://github.com/googleapis/java-bigquery @@ -53,7 +53,7 @@ UTF-8 github google-cloud-bigquery-parent - v2-rev20211106-1.32.1 + v2-rev20211129-1.32.1 2.5.1 @@ -67,6 +67,14 @@ import + + com.google.cloud + google-cloud-datacatalog-bom + 1.6.1 + pom + import + + org.checkerframework checker-compat-qual @@ -76,7 +84,7 @@ com.google.cloud google-cloud-bigquery - 2.5.1 + 2.6.0 @@ -107,25 +115,13 @@ org.mockito mockito-core - 4.1.0 + 4.2.0 test com.google.cloud google-cloud-storage - 2.2.1 - test - - - com.google.cloud - google-cloud-datacatalog - 1.6.0 - test - - - com.google.api.grpc - proto-google-cloud-datacatalog-v1 - 1.6.0 + 2.2.2 test diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 903a7915b8..092fd82b23 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -30,7 +30,7 @@ com.google.cloud.samples shared-configuration - 1.0.23 + 1.2.0 @@ -45,7 +45,7 @@ com.google.cloud google-cloud-bigquery - 2.5.0 + 2.5.1 @@ -63,13 +63,13 @@ com.google.cloud google-cloud-bigtable - 2.3.0 + 2.4.0 test com.google.cloud google-cloud-bigqueryconnection - 2.1.6 + 2.1.7 test diff --git a/samples/pom.xml b/samples/pom.xml index f2bb68bedb..4e9299af44 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -34,7 +34,7 @@ com.google.cloud.samples shared-configuration - 1.0.23 + 1.2.0 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 04da45ef81..a733801707 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -30,7 +30,7 @@ com.google.cloud.samples shared-configuration - 1.0.23 + 1.2.0 @@ -44,7 +44,7 @@ com.google.cloud google-cloud-bigquery - 2.5.1 + 2.6.0 @@ -61,13 +61,13 @@ com.google.cloud google-cloud-bigtable - 2.3.0 + 2.4.0 test com.google.cloud google-cloud-bigqueryconnection - 2.1.6 + 2.1.7 test diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 69d68ada6b..be5a9645ea 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -29,7 +29,7 @@ com.google.cloud.samples shared-configuration - 1.0.23 + 1.2.0 @@ -47,7 +47,7 @@ com.google.cloud libraries-bom - 24.0.0 + 24.1.1 pom import @@ -79,13 +79,13 @@ com.google.cloud google-cloud-bigtable - 2.3.0 + 2.4.0 test com.google.cloud google-cloud-bigqueryconnection - 2.1.6 + 2.1.7 test @@ -100,7 +100,9 @@ 1.1.3 test + + diff --git a/samples/snippets/src/main/java/com/example/bigquery/AlterMaterializedView.java b/samples/snippets/src/main/java/com/example/bigquery/UpdateMaterializedView.java similarity index 79% rename from samples/snippets/src/main/java/com/example/bigquery/AlterMaterializedView.java rename to samples/snippets/src/main/java/com/example/bigquery/UpdateMaterializedView.java index 8ce25196f3..4de1273443 100644 --- a/samples/snippets/src/main/java/com/example/bigquery/AlterMaterializedView.java +++ b/samples/snippets/src/main/java/com/example/bigquery/UpdateMaterializedView.java @@ -16,7 +16,7 @@ package com.example.bigquery; -// [START bigquery_alter_materialized_view] +// [START bigquery_update_materialized_view] import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryException; import com.google.cloud.bigquery.BigQueryOptions; @@ -24,17 +24,17 @@ import com.google.cloud.bigquery.Table; import com.google.cloud.bigquery.TableId; -// Sample to alter materialized view -public class AlterMaterializedView { +// Sample to update materialized view +public class UpdateMaterializedView { public static void main(String[] args) { // TODO(developer): Replace these variables before running the sample. String datasetName = "MY_DATASET_NAME"; String materializedViewName = "MY_MATERIALIZED_VIEW_NAME"; - alterMaterializedView(datasetName, materializedViewName); + updateMaterializedView(datasetName, materializedViewName); } - public static void alterMaterializedView(String datasetName, String materializedViewName) { + public static void updateMaterializedView(String datasetName, String materializedViewName) { try { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. @@ -45,17 +45,17 @@ public static void alterMaterializedView(String datasetName, String materialized // Get existing materialized view Table table = bigquery.getTable(tableId); MaterializedViewDefinition materializedViewDefinition = table.getDefinition(); - // Alter materialized view + // Update materialized view materializedViewDefinition .toBuilder() .setEnableRefresh(true) .setRefreshIntervalMs(1000L) .build(); table.toBuilder().setDefinition(materializedViewDefinition).build().update(); - System.out.println("Materialized view altered successfully"); + System.out.println("Materialized view updated successfully"); } catch (BigQueryException e) { - System.out.println("Materialized view was not altered. \n" + e.toString()); + System.out.println("Materialized view was not updated. \n" + e.toString()); } } } -// [END bigquery_alter_materialized_view] +// [END bigquery_update_materialized_view] diff --git a/samples/snippets/src/test/java/com/example/bigquery/AlterMaterializedViewIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java similarity index 90% rename from samples/snippets/src/test/java/com/example/bigquery/AlterMaterializedViewIT.java rename to samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java index 3cc5dfa7c4..54ed2194a4 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/AlterMaterializedViewIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/UpdateMaterializedViewIT.java @@ -32,7 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; -public class AlterMaterializedViewIT { +public class UpdateMaterializedViewIT { private static final String ID = UUID.randomUUID().toString().substring(0, 8); private final Logger log = Logger.getLogger(this.getClass().getName()); @@ -65,7 +65,7 @@ public void setUp() { System.setOut(out); tableName = "MY_TABLE_NAME_TEST_" + ID; - materializedViewName = "MY_ALTER_MATERIALIZED_VIEW_NAME_TEST_" + ID; + materializedViewName = "MY_UPDATE_MATERIALIZED_VIEW_NAME_TEST_" + ID; Schema schema = Schema.of( @@ -95,8 +95,8 @@ public void tearDown() { } @Test - public void testAlterMaterializedView() { - AlterMaterializedView.alterMaterializedView(BIGQUERY_DATASET_NAME, materializedViewName); - assertThat(bout.toString()).contains("Materialized view altered successfully"); + public void testUpdateMaterializedView() { + UpdateMaterializedView.updateMaterializedView(BIGQUERY_DATASET_NAME, materializedViewName); + assertThat(bout.toString()).contains("Materialized view updated successfully"); } } diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java index e9f03e87e5..1e3b8980f9 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java @@ -24,8 +24,9 @@ import com.google.cloud.bigquery.StandardSQLTypeName; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.UUID; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.junit.After; @@ -81,7 +82,8 @@ public void tearDown() { @Test public void testUpdateTableExpiration() { - Long newExpiration = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); + // Set new expiration to a week from Now + Long newExpiration = Instant.now().plus(7, ChronoUnit.DAYS).toEpochMilli(); UpdateTableExpiration.updateTableExpiration(BIGQUERY_DATASET_NAME, tableName, newExpiration); assertThat(bout.toString()).contains("Table expiration updated successfully"); } diff --git a/versions.txt b/versions.txt index 1b2ae277d4..b8903da9c1 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:2.5.1:2.5.1 \ No newline at end of file +google-cloud-bigquery:2.6.0:2.6.0 \ No newline at end of file