diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 6b83f060e..91bb69e63 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:9bf82029163bc06d58f56682afd1893a42ace3e04b0359accb86f79c6ecdc9f9 + digest: sha256:bf5639d265d70f6137d57d42ae781a6f4e26d4085ff4e018e71350480f9b3996 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 000000000..66048b5a0 --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,72 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '0 0 * * *' + push: + branches: [ "main" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + # Uncomment the permissions below if installing in a private repository. + # contents: read + # actions: read + + steps: + - name: "Checkout code" + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecard on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@168b99b3c22180941ae7dbdd5f5c9678ede476ba # v2.2.7 + with: + sarif_file: results.sarif diff --git a/CHANGELOG.md b/CHANGELOG.md index 7757dfd59..0f8c0eca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## [2.24.0](https://github.com/googleapis/java-bigquery/compare/v2.23.2...v2.24.0) (2023-03-21) + + +### Features + +* Add support for clone ([#2553](https://github.com/googleapis/java-bigquery/issues/2553)) ([2186c64](https://github.com/googleapis/java-bigquery/commit/2186c64e523e030a777eec447bc1f22802f56617)) + + +### Dependencies + +* Update actions/checkout action to v3.4.0 ([#2575](https://github.com/googleapis/java-bigquery/issues/2575)) ([6935a1e](https://github.com/googleapis/java-bigquery/commit/6935a1e353d496e6de656de3431563b3527456e5)) +* Update actions/upload-artifact action to v3.1.2 ([#2571](https://github.com/googleapis/java-bigquery/issues/2571)) ([aa0c70e](https://github.com/googleapis/java-bigquery/commit/aa0c70ec6fe0ae859b0944101373ebabb0bb4600)) +* Update cloud client dependencies ([#2583](https://github.com/googleapis/java-bigquery/issues/2583)) ([dcacc31](https://github.com/googleapis/java-bigquery/commit/dcacc3150b3dbcd9c54038035cec3a7b1946af6c)) +* Update dependency com.google.api.grpc:proto-google-cloud-bigqueryconnection-v1 to v2.15.0 ([#2577](https://github.com/googleapis/java-bigquery/issues/2577)) ([eaf09d6](https://github.com/googleapis/java-bigquery/commit/eaf09d65c00a742732b918478021dde3b12ac1bd)) +* Update dependency com.google.apis:google-api-services-bigquery to v2-rev20230311-2.0.0 ([#2578](https://github.com/googleapis/java-bigquery/issues/2578)) ([aab037c](https://github.com/googleapis/java-bigquery/commit/aab037c8eb676b42231c99b5890c991095d2f8c2)) +* Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.5.0 ([#2580](https://github.com/googleapis/java-bigquery/issues/2580)) ([1764eeb](https://github.com/googleapis/java-bigquery/commit/1764eeb8d56ab3e5bda9b554414b5fe4d022fb72)) +* Update dependency com.google.cloud:google-cloud-storage to v2.20.0 ([#2559](https://github.com/googleapis/java-bigquery/issues/2559)) ([8a854db](https://github.com/googleapis/java-bigquery/commit/8a854dbdcb676e2b2873ddfadf514f2e401fe987)) +* Update github/codeql-action action to v2.2.7 ([#2572](https://github.com/googleapis/java-bigquery/issues/2572)) ([105f5ee](https://github.com/googleapis/java-bigquery/commit/105f5ee8d8882f79688dec685f20f44817bf313a)) + ## [2.23.2](https://github.com/googleapis/java-bigquery/compare/v2.23.1...v2.23.2) (2023-03-07) diff --git a/README.md b/README.md index 907a391fb..daeb668e5 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 - 26.8.0 + 26.10.0 pom import @@ -44,7 +44,7 @@ If you are using Maven without BOM, add this to your dependencies: com.google.cloud google-cloud-bigquery - 2.23.0 + 2.23.2 ``` @@ -52,21 +52,22 @@ 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:26.9.0') +implementation platform('com.google.cloud:libraries-bom:26.10.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.23.1' +implementation 'com.google.cloud:google-cloud-bigquery:2.23.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.23.1" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.23.2" ``` + ## Authentication @@ -83,7 +84,7 @@ The client application making API calls must be granted [authorization scopes][a You will need a [Google Cloud Platform Console][developer-console] project with the Cloud BigQuery [API enabled][enable-api]. You will need to [enable billing][enable-billing] to use Google Cloud BigQuery. [Follow these instructions][create-project] to get your project set up. You will also need to set up the local development environment by -[installing the Google Cloud SDK][cloud-sdk] and running the following commands in command line: +[installing the Google Cloud Command Line Interface][cloud-cli] and running the following commands in command line: `gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`. ### Installation and setup @@ -128,6 +129,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-bigquery/tree | Create Clustered Table | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateClusteredTable.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/CreateClusteredTable.java) | | Create Dataset | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateDataset.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/CreateDataset.java) | | Create Dataset Aws | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateDatasetAws.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/CreateDatasetAws.java) | +| Create Dataset With Regional Endpoint | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateDatasetWithRegionalEndpoint.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/CreateDatasetWithRegionalEndpoint.java) | | Create External Table Aws | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateExternalTableAws.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/CreateExternalTableAws.java) | | Create Iam Policy | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateIamPolicy.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/CreateIamPolicy.java) | | Create Job | [source code](https://github.com/googleapis/java-bigquery/blob/main/samples/snippets/src/main/java/com/example/bigquery/CreateJob.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/CreateJob.java) | @@ -346,14 +348,14 @@ 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://search.maven.org/search?q=g:com.google.cloud%20AND%20a:google-cloud-bigquery&core=gav +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.23.2 [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 [iam-policy]: https://cloud.google.com/iam/docs/overview#cloud-iam-policy [developer-console]: https://console.developers.google.com/ [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects -[cloud-sdk]: https://cloud.google.com/sdk/ +[cloud-cli]: https://cloud.google.com/cli [troubleshooting]: https://github.com/googleapis/google-cloud-common/blob/main/troubleshooting/readme.md#troubleshooting [contributing]: https://github.com/googleapis/java-bigquery/blob/main/CONTRIBUTING.md [code-of-conduct]: https://github.com/googleapis/java-bigquery/blob/main/CODE_OF_CONDUCT.md#contributor-code-of-conduct diff --git a/benchmark/pom.xml b/benchmark/pom.xml index 177ce5af8..28835f3c6 100644 --- a/benchmark/pom.xml +++ b/benchmark/pom.xml @@ -6,7 +6,7 @@ google-cloud-bigquery-parent com.google.cloud - 2.23.2 + 2.24.0 diff --git a/google-cloud-bigquery/clirr-ignored-differences.xml b/google-cloud-bigquery/clirr-ignored-differences.xml index 6386c5037..5fe634cca 100644 --- a/google-cloud-bigquery/clirr-ignored-differences.xml +++ b/google-cloud-bigquery/clirr-ignored-differences.xml @@ -44,4 +44,10 @@ com/google/cloud/bigquery/TableInfo* *DefaultCollation(*) + + + 7013 + com/google/cloud/bigquery/TableInfo* + *CloneDefinition(*) + \ No newline at end of file diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index 2f7613e52..f4555ed2b 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.23.2 + 2.24.0 jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,7 +11,7 @@ com.google.cloud google-cloud-bigquery-parent - 2.23.2 + 2.24.0 google-cloud-bigquery diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CloneDefinition.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CloneDefinition.java new file mode 100644 index 000000000..58594fe32 --- /dev/null +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CloneDefinition.java @@ -0,0 +1,85 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.bigquery; + +import com.google.api.client.util.DateTime; +import com.google.api.core.BetaApi; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.VisibleForTesting; +import java.io.Serializable; +import javax.annotation.Nullable; + +@AutoValue +@BetaApi +public abstract class CloneDefinition implements Serializable { + + private static final long serialVersionUID = 1460853787400450649L; + + public static Builder newBuilder() { + return new AutoValue_CloneDefinition.Builder(); + } + + static CloneDefinition fromPb( + com.google.api.services.bigquery.model.CloneDefinition cloneDefinition) { + Builder builder = newBuilder(); + + if (cloneDefinition.getCloneTime() != null) { + builder.setCloneTime(cloneDefinition.getCloneTime().toString()); + } + if (cloneDefinition.getBaseTableReference() != null) { + builder.setBaseTableId(TableId.fromPb(cloneDefinition.getBaseTableReference())); + } + + return builder.build(); + } + + @Nullable + public abstract TableId getBaseTableId(); + + @Nullable + public abstract String getCloneTime(); + + /** Returns a builder for a Clone table definition. */ + @VisibleForTesting + public abstract Builder toBuilder(); + + com.google.api.services.bigquery.model.CloneDefinition toPb() { + + com.google.api.services.bigquery.model.CloneDefinition cloneDefinition = + new com.google.api.services.bigquery.model.CloneDefinition(); + cloneDefinition.setBaseTableReference(getBaseTableId().toPb()); + cloneDefinition.setCloneTime(DateTime.parseRfc3339(getCloneTime())); + + return cloneDefinition; + } + + @AutoValue.Builder + public abstract static class Builder { + + /** Reference describing the ID of the table that was Cloned. * */ + public abstract Builder setBaseTableId(TableId baseTableId); + + /** + * The time at which the base table was Cloned. This value is reported in the JSON response + * using RFC3339 format. * + */ + public abstract Builder setCloneTime(String dateTime); + + /** Creates a {@code CloneDefinition} object. */ + public abstract CloneDefinition build(); + } +} diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java index fe67986fc..37955fec0 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java @@ -128,8 +128,8 @@ public Builder setDestinationTable(TableId destinationTable) { } /** - * Sets the supported operation types (COPY, SNAPSHOT or RESTORE) in table copy job. More info: - * https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#operationtype + * Sets the supported operation types (COPY, CLONE, SNAPSHOT or RESTORE) in table copy job. More + * info: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#operationtype */ public Builder setOperationType(String operationType) { this.operationType = operationType; diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java index 8303566d2..3e67e8d75 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java @@ -162,6 +162,12 @@ public Builder setDefaultCollation(String defaultCollation) { return this; } + @Override + public TableInfo.Builder setCloneDefinition(CloneDefinition cloneDefinition) { + infoBuilder.setCloneDefinition(cloneDefinition); + return this; + } + @Override public Table build() { return new Table(bigquery, infoBuilder); diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java index cfe700300..19e9de2b7 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java @@ -74,6 +74,8 @@ public Table apply(TableInfo tableInfo) { private final Boolean requirePartitionFilter; private final String defaultCollation; + private final CloneDefinition cloneDefinition; + /** A builder for {@code TableInfo} objects. */ public abstract static class Builder { @@ -138,6 +140,8 @@ public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) { } public abstract Builder setDefaultCollation(String defaultCollation); + + public abstract Builder setCloneDefinition(CloneDefinition cloneDefinition); } static class BuilderImpl extends Builder { @@ -159,6 +163,7 @@ static class BuilderImpl extends Builder { private Labels labels = Labels.ZERO; private Boolean requirePartitionFilter; private String defaultCollation; + private CloneDefinition cloneDefinition; BuilderImpl() {} @@ -180,6 +185,7 @@ static class BuilderImpl extends Builder { this.labels = tableInfo.labels; this.requirePartitionFilter = tableInfo.requirePartitionFilter; this.defaultCollation = tableInfo.defaultCollation; + this.cloneDefinition = tableInfo.cloneDefinition; } BuilderImpl(Table tablePb) { @@ -205,6 +211,9 @@ static class BuilderImpl extends Builder { this.labels = Labels.fromPb(tablePb.getLabels()); this.requirePartitionFilter = tablePb.getRequirePartitionFilter(); this.defaultCollation = tablePb.getDefaultCollation(); + if (tablePb.getCloneDefinition() != null) { + this.cloneDefinition = CloneDefinition.fromPb(tablePb.getCloneDefinition()); + } } @Override @@ -309,6 +318,11 @@ public Builder setDefaultCollation(String defaultCollation) { return this; } + public Builder setCloneDefinition(CloneDefinition cloneDefinition) { + this.cloneDefinition = cloneDefinition; + return this; + } + @Override public TableInfo build() { return new TableInfo(this); @@ -333,6 +347,7 @@ public TableInfo build() { this.labels = builder.labels; this.requirePartitionFilter = builder.requirePartitionFilter; this.defaultCollation = builder.defaultCollation; + this.cloneDefinition = builder.cloneDefinition; } /** Returns the hash of the table resource. */ @@ -439,6 +454,10 @@ public String getDefaultCollation() { return defaultCollation; } + public CloneDefinition getCloneDefinition() { + return cloneDefinition; + } + /** Returns a builder for the table object. */ public Builder toBuilder() { return new BuilderImpl(this); @@ -464,6 +483,7 @@ public String toString() { .add("labels", labels) .add("requirePartitionFilter", requirePartitionFilter) .add("defaultCollation", defaultCollation) + .add("cloneDefinition", cloneDefinition) .toString(); } @@ -528,6 +548,9 @@ Table toPb() { if (defaultCollation != null) { tablePb.setDefaultCollation(defaultCollation); } + if (cloneDefinition != null) { + tablePb.setCloneDefinition(cloneDefinition.toPb()); + } return tablePb; } diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/package-info.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/package-info.java index 65f801357..cbd283fca 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/package-info.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/package-info.java @@ -18,30 +18,26 @@ * A client for BigQuery – A fully managed, petabyte scale, low cost enterprise data warehouse for * analytics. * - *

A simple usage example showing how to create a table if it does not exist and load data into - * it. For the complete source code see - * CreateTableAndLoadData.java. + *

A simple usage example showing how to create a table in Bigquery. For the complete source code see + * CreateTable.java. * *

{@code
- * BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
- * TableId tableId = TableId.of("dataset", "table");
- * Table table = bigquery.getTable(tableId);
- * if (table == null) {
- *   System.out.println("Creating table " + tableId);
- *   Field integerField = Field.of("fieldName", Field.Type.integer());
- *   Schema schema = Schema.of(integerField);
- *   table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
- * }
- * System.out.println("Loading data into table " + tableId);
- * Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path");
- * loadJob = loadJob.waitFor();
- * if (loadJob.getStatus().getError() != null) {
- *   System.out.println("Job completed with errors");
- * } else {
- *   System.out.println("Job succeeded");
- * }
- * }
+ * 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. + * BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); + * + * TableId tableId = TableId.of(datasetName, tableName); + * TableDefinition tableDefinition = StandardTableDefinition.of(schema); + * TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build(); + * + * bigquery.create(tableInfo); + * System.out.println("Table created successfully"); + * } catch (BigQueryException e) { + * System.out.println("Table was not created. \n" + e.toString()); + * } + * * * @see Google Cloud BigQuery */ diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java index 6e5b32419..c2e6c03f5 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java @@ -17,7 +17,14 @@ /** * A testing helper for Google BigQuery. * - *

A simple usage example: + *

A simple usage example: 1. Create a test Google Cloud project. + * + *

2. Download a JSON service account credentials file from the Google Developer's Console. + * + *

3. Create a RemoteBigQueryHelper object using your project ID and JSON key. Here is an example + * that uses the RemoteBigQueryHelper to create a dataset. + * + *

4. Run tests. * *

Before the test: * @@ -33,9 +40,5 @@ *

{@code
  * RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
  * }
- * - * @see - * Google Cloud Java tools for testing */ package com.google.cloud.bigquery.testing; diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/CloneDefinitionTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/CloneDefinitionTest.java new file mode 100644 index 000000000..33bcf5f40 --- /dev/null +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/CloneDefinitionTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.bigquery; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class CloneDefinitionTest { + private static final TableId BASE_TABLE_ID = TableId.of("DATASET_NAME", "BASE_TABLE_NAME"); + private static final String CLONE_TIME = "2021-05-19T11:32:26.553Z"; + private static final CloneDefinition CLONETABLE_DEFINITION = + CloneDefinition.newBuilder().setBaseTableId(BASE_TABLE_ID).setCloneTime(CLONE_TIME).build(); + + @Test + public void testToBuilder() { + compareCloneTableDefinition(CLONETABLE_DEFINITION, CLONETABLE_DEFINITION.toBuilder().build()); + CloneDefinition cloneTableDefinition = + CLONETABLE_DEFINITION.toBuilder().setCloneTime("2021-05-20T11:32:26.553Z").build(); + assertEquals("2021-05-20T11:32:26.553Z", cloneTableDefinition.getCloneTime()); + } + + @Test + public void testBuilder() { + assertEquals(BASE_TABLE_ID, CLONETABLE_DEFINITION.getBaseTableId()); + assertEquals(CLONE_TIME, CLONETABLE_DEFINITION.getCloneTime()); + CloneDefinition cloneDefinition = + CloneDefinition.newBuilder().setBaseTableId(BASE_TABLE_ID).setCloneTime(CLONE_TIME).build(); + assertEquals(CLONETABLE_DEFINITION, cloneDefinition); + } + + @Test + public void testToAndFromPb() { + CloneDefinition cloneDefinition = CLONETABLE_DEFINITION.toBuilder().build(); + assertTrue(CloneDefinition.fromPb(cloneDefinition.toPb()) instanceof CloneDefinition); + compareCloneTableDefinition(cloneDefinition, CloneDefinition.fromPb(cloneDefinition.toPb())); + } + + private void compareCloneTableDefinition(CloneDefinition expected, CloneDefinition value) { + assertEquals(expected.getBaseTableId(), value.getBaseTableId()); + assertEquals(expected.getCloneTime(), value.getCloneTime()); + } +} 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 0bbe1efdd..bf59c2b67 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 @@ -54,6 +54,7 @@ import com.google.cloud.bigquery.BigQueryException; import com.google.cloud.bigquery.BigQueryResult; import com.google.cloud.bigquery.BigQuerySQLException; +import com.google.cloud.bigquery.CloneDefinition; import com.google.cloud.bigquery.Clustering; import com.google.cloud.bigquery.Connection; import com.google.cloud.bigquery.ConnectionProperty; @@ -4334,6 +4335,7 @@ public void testSnapshotTableCopyJob() throws InterruptedException { assertNotNull(snapshotTable); assertEquals(snapshotTableId.getDataset(), snapshotTable.getTableId().getDataset()); assertEquals(snapshotTableName, snapshotTable.getTableId().getTable()); + System.out.println(snapshotTable.getDefinition()); assertTrue(snapshotTable.getDefinition() instanceof SnapshotTableDefinition); assertEquals(DDL_TABLE_SCHEMA, snapshotTable.getDefinition().getSchema()); assertNotNull(((SnapshotTableDefinition) snapshotTable.getDefinition()).getSnapshotTime()); @@ -5179,4 +5181,56 @@ public void testCreateExternalTableWithReferenceFileSchemaParquet() { boolean success = bigquery.delete(tableId); assertEquals(true, success); } + + @Test + public void testCloneTableCopyJob() throws InterruptedException { + String sourceTableName = "test_copy_job_base_table"; + String ddlTableName = TABLE_ID_DDL.getTable(); + String cloneTableName = String.format("test_clone_table"); + // Create source table with some data in it + String ddlQuery = + String.format( + "CREATE OR REPLACE TABLE %s (" + + "TimestampField TIMESTAMP OPTIONS(description='TimestampDescription'), " + + "StringField STRING OPTIONS(description='StringDescription'), " + + "BooleanField BOOLEAN OPTIONS(description='BooleanDescription') " + + ") AS SELECT * FROM %s", + sourceTableName, ddlTableName); + QueryJobConfiguration ddlConfig = + QueryJobConfiguration.newBuilder(ddlQuery).setDefaultDataset(DatasetId.of(DATASET)).build(); + TableId sourceTableId = TableId.of(DATASET, sourceTableName); + TableResult result = bigquery.query(ddlConfig); + assertEquals(DDL_TABLE_SCHEMA, result.getSchema()); + Table remoteTable = bigquery.getTable(DATASET, sourceTableName); + assertNotNull(remoteTable); + + // Create clone table using source table as the base table + TableId cloneTableId = TableId.of(DATASET, cloneTableName); + CopyJobConfiguration cloneConfiguration = + CopyJobConfiguration.newBuilder(cloneTableId, sourceTableId) + .setOperationType("CLONE") + .build(); + Job createdJob = bigquery.create(JobInfo.of(cloneConfiguration)); + CopyJobConfiguration createdConfiguration = createdJob.getConfiguration(); + assertNotNull(createdConfiguration.getSourceTables()); + assertNotNull(createdConfiguration.getOperationType()); + assertNotNull(createdConfiguration.getDestinationTable()); + Job completedJob = createdJob.waitFor(); + assertNull(completedJob.getStatus().getError()); + + Table cloneTable = bigquery.getTable(DATASET, cloneTableName); + assertNotNull(cloneTable); + assertEquals(cloneTableId.getDataset(), cloneTable.getTableId().getDataset()); + assertEquals(cloneTableName, cloneTable.getTableId().getTable()); + assertEquals(TableDefinition.Type.TABLE, cloneTable.getDefinition().getType()); + assertTrue(cloneTable.getDefinition() instanceof StandardTableDefinition); + assertEquals(DDL_TABLE_SCHEMA, cloneTable.getDefinition().getSchema()); + assertTrue(cloneTable.getCloneDefinition() instanceof CloneDefinition); + assertEquals(sourceTableName, cloneTable.getCloneDefinition().getBaseTableId().getTable()); + assertNotNull(cloneTable.getCloneDefinition().getCloneTime()); + + // Clean up + assertTrue(remoteTable.delete()); + assertTrue(cloneTable.delete()); + } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITRemoteUDFTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITRemoteUDFTest.java index 7e74a8f4c..7a3194e52 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITRemoteUDFTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITRemoteUDFTest.java @@ -47,7 +47,7 @@ public class ITRemoteUDFTest { private static final String ID = UUID.randomUUID().toString().substring(0, 8); private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); - private static final String CONNECTION_ID = "test-connectin-id-" + ID; + private static final String CONNECTION_ID = "test-connection-id-" + ID; private static final String LOCATION = "US"; private static final String PARENT = LocationName.of(PROJECT_ID, LOCATION).toString(); private static final String REMOTE_ENDPOINT = "https://aaabbbccc-uc.a.run.app/"; diff --git a/pom.xml b/pom.xml index 1a0439262..cb264307e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 2.23.2 + 2.24.0 BigQuery Parent https://github.com/googleapis/java-bigquery @@ -53,8 +53,8 @@ UTF-8 github google-cloud-bigquery-parent - v2-rev20230210-2.0.0 - 3.4.0 + v2-rev20230311-2.0.0 + 3.5.0 11.0.0
@@ -72,7 +72,7 @@ com.google.cloud google-cloud-bigquerystorage-bom - 2.33.1 + 2.34.0 pom import @@ -96,7 +96,7 @@ com.google.cloud google-cloud-datacatalog-bom - 1.18.0 + 1.19.0 pom import @@ -110,7 +110,7 @@ com.google.cloud google-cloud-bigquery - 2.23.2 + 2.24.0 @@ -154,19 +154,19 @@ com.google.cloud google-cloud-storage - 2.19.0 + 2.20.1 test com.google.cloud google-cloud-bigqueryconnection - 2.14.0 + 2.15.0 test com.google.api.grpc proto-google-cloud-bigqueryconnection-v1 - 2.14.0 + 2.15.0 test diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index d896f4f2b..520236a79 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -45,7 +45,7 @@ com.google.cloud google-cloud-bigquery - 2.23.0 + 2.23.2 @@ -69,7 +69,7 @@ com.google.cloud google-cloud-bigqueryconnection - 2.14.0 + 2.15.0 test diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml index eafb3e8f3..5fe55f393 100644 --- a/samples/native-image-sample/pom.xml +++ b/samples/native-image-sample/pom.xml @@ -39,7 +39,7 @@ com.google.cloud libraries-bom - 26.8.0 + 26.10.0 pom import @@ -111,7 +111,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.0.0 **/*IT diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 8bdcef7c0..456b40bd0 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-bigquery - 2.23.2 + 2.24.0 @@ -67,7 +67,7 @@ com.google.cloud google-cloud-bigqueryconnection - 2.14.0 + 2.15.0 test diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 7321e1338..76715c4cc 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -47,7 +47,7 @@ com.google.cloud libraries-bom - 26.8.0 + 26.10.0 pom import @@ -85,7 +85,7 @@ com.google.cloud google-cloud-bigqueryconnection - 2.14.0 + 2.15.0 test diff --git a/samples/snippets/src/main/java/com/example/bigquery/CreateDatasetWithRegionalEndpoint.java b/samples/snippets/src/main/java/com/example/bigquery/CreateDatasetWithRegionalEndpoint.java new file mode 100644 index 000000000..c19a93b42 --- /dev/null +++ b/samples/snippets/src/main/java/com/example/bigquery/CreateDatasetWithRegionalEndpoint.java @@ -0,0 +1,49 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.bigquery; + +// [START bigquery_create_dataset_with_regional_endpoint] +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Dataset; +import com.google.cloud.bigquery.DatasetInfo; + +public class CreateDatasetWithRegionalEndpoint { + public static void createDatasetWithRegionalEndpoint() { + BigQuery bigquery; + 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. + bigquery = + BigQueryOptions.newBuilder() + .setHost("https://us-east4-bigquery.googleapis.com/") + .build() + .getService(); + String datasetName = "MyRegionalDataset"; + + DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build(); + + Dataset newDataset = bigquery.create(datasetInfo); + System.out.println("Region of dataset: " + newDataset.getLocation()); + bigquery.delete("MyRegionalDataset"); + } catch (BigQueryException e) { + System.out.println("Dataset was not created. \n" + e); + } + } +} +// [END bigquery_create_dataset_with_regional_endpoint] diff --git a/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java b/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java new file mode 100644 index 000000000..da6f4afd7 --- /dev/null +++ b/samples/snippets/src/test/java/com/example/bigquery/CreateDatasetWithRegionalEndpointIT.java @@ -0,0 +1,56 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.bigquery; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CreateDatasetWithRegionalEndpointIT { + private final Logger log = Logger.getLogger(this.getClass().getName()); + private ByteArrayOutputStream bout; + private PrintStream out; + private PrintStream originalPrintStream; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + originalPrintStream = System.out; + System.setOut(out); + } + + @After + public void tearDown() { + // restores print statements in the original method + System.out.flush(); + System.setOut(originalPrintStream); + log.log(Level.INFO, "\n" + bout.toString()); + } + + @Test + public void testCreateDatasetWithRegionalEndpoint() { + CreateDatasetWithRegionalEndpoint.createDatasetWithRegionalEndpoint(); + assertThat(bout.toString().contains("Region of dataset: us-east4")); + } +} diff --git a/versions.txt b/versions.txt index 777c20067..167ebdeeb 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:2.23.2:2.23.2 \ No newline at end of file +google-cloud-bigquery:2.24.0:2.24.0 \ No newline at end of file