diff --git a/.github/trusted-contribution.yml b/.github/trusted-contribution.yml new file mode 100644 index 000000000..f247d5c78 --- /dev/null +++ b/.github/trusted-contribution.yml @@ -0,0 +1,2 @@ +trustedContributors: +- renovate-bot \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 61708ac20..b14a1bebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## [1.107.0](https://www.github.com/googleapis/java-bigquery/compare/v1.106.0...v1.107.0) (2020-02-19) + + +### Features + +* expose location field of model ([#175](https://www.github.com/googleapis/java-bigquery/issues/175)) ([646c2b4](https://www.github.com/googleapis/java-bigquery/commit/646c2b43b2ccbc609e0d5b85a7e4fbf502bb1243)) +* expose slotms field in querystage ([#172](https://www.github.com/googleapis/java-bigquery/issues/172)) ([4a82b3c](https://www.github.com/googleapis/java-bigquery/commit/4a82b3cd1aa821d72efc7046329db075c10ae344)) + + +### Bug Fixes + +* allUsers access ([#178](https://www.github.com/googleapis/java-bigquery/issues/178)) ([7464e23](https://www.github.com/googleapis/java-bigquery/commit/7464e234c00da047a06744eef6c7f281d90217cd)) + + +### Dependencies + +* update core dependencies to v1.92.5 ([#162](https://www.github.com/googleapis/java-bigquery/issues/162)) ([6ea4141](https://www.github.com/googleapis/java-bigquery/commit/6ea41413aed3d6cc81b9c4995a21f1017e268c74)) +* update core transport dependencies to v1.34.2 ([#168](https://www.github.com/googleapis/java-bigquery/issues/168)) ([c35069d](https://www.github.com/googleapis/java-bigquery/commit/c35069d4e91939e51f2101f2b8f93d2f67c089c5)) +* update dependency com.google.apis:google-api-services-bigquery to v2-rev20191211-1.30.8 ([#161](https://www.github.com/googleapis/java-bigquery/issues/161)) ([54872ba](https://www.github.com/googleapis/java-bigquery/commit/54872ba95ff0903817df217dfa6da883d43e6ace)) +* update dependency com.google.cloud:libraries-bom to v4 ([#159](https://www.github.com/googleapis/java-bigquery/issues/159)) ([95e4ff0](https://www.github.com/googleapis/java-bigquery/commit/95e4ff068dd8650ec0acebbe23e958c6e361ed36)) +* update dependency com.google.cloud:libraries-bom to v4.0.1 ([#167](https://www.github.com/googleapis/java-bigquery/issues/167)) ([633ea52](https://www.github.com/googleapis/java-bigquery/commit/633ea52ddc3677e8091c1f69283a864929227a17)) +* update dependency com.google.cloud:libraries-bom to v4.1.0 ([#170](https://www.github.com/googleapis/java-bigquery/issues/170)) ([6acedda](https://www.github.com/googleapis/java-bigquery/commit/6aceddad33da3055b24a8ae0420c25d85cfb09fb)) +* update dependency com.google.protobuf:protobuf-java to v3.11.4 ([#171](https://www.github.com/googleapis/java-bigquery/issues/171)) ([6f292f5](https://www.github.com/googleapis/java-bigquery/commit/6f292f52728992bfeb511b97b1dd778e1ef8db2c)) +* update dependency io.grpc:grpc-bom to v1.27.1 ([#169](https://www.github.com/googleapis/java-bigquery/issues/169)) ([5212b2f](https://www.github.com/googleapis/java-bigquery/commit/5212b2f892074be36204fa9ef3e2dff7474828eb)) + + +### Documentation + +* broken links ([#154](https://www.github.com/googleapis/java-bigquery/issues/154)) ([e060aba](https://www.github.com/googleapis/java-bigquery/commit/e060aba2ed030a13e50f5e0f5597b3e04ad9c292)) + ## [1.106.0](https://www.github.com/googleapis/java-bigquery/compare/v1.105.0...v1.106.0) (2020-02-03) diff --git a/README.md b/README.md index acb4556ed..5c312655f 100644 --- a/README.md +++ b/README.md @@ -37,22 +37,22 @@ If you are using Maven without a BOM, add this to your dependencies. com.google.cloud google-cloud-bigquery - 1.106.0 + 1.107.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-bigquery:1.106.0' +compile 'com.google.cloud:google-cloud-bigquery:1.107.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.106.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.107.0" ``` [//]: # ({x-version-update-end}) Example Application ------------------- -- [`BigQueryExample`](../../google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality. +- [`BigQueryExample`](https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality. Read more about using this application on the [`BigQueryExample` docs page](https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/examples/bigquery/BigQueryExample.html). Authentication @@ -205,7 +205,7 @@ for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) { #### Complete source code In -[InsertDataAndQueryTable.java](../../google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/InsertDataAndQueryTable.java) +[InsertDataAndQueryTable.java](https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/InsertDataAndQueryTable.java) we put together all the code shown above into one program. The program assumes that you are running on Compute Engine or from your own desktop. To run the example on App Engine, simply move the code from the main method to your application's servlet class and change the print statements to diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index e6122cd19..c6696d73c 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 - 1.106.0 + 1.107.0 jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,7 +11,7 @@ com.google.cloud google-cloud-bigquery-parent - 1.106.0 + 1.107.0 google-cloud-bigquery diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index 746f1542c..4da7fe5e6 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -103,7 +103,8 @@ public enum Type { DOMAIN, GROUP, USER, - VIEW + VIEW, + IAM_MEMBER } Entity(Type type) { @@ -132,6 +133,9 @@ static Entity fromPb(Access access) { if (access.getView() != null) { return new View(TableId.fromPb(access.getView())); } + if (access.getIamMember() != null) { + return new IamMember(access.getIamMember()); + } // Unreachable throw new BigQueryException( BigQueryException.UNKNOWN_CODE, "Unrecognized access configuration"); @@ -383,6 +387,53 @@ Access toPb() { } } + /** + * Class for a BigQuery IamMember entity. Objects of this class represent a iamMember to grant + * access to given the IAM Policy. + */ + public static final class IamMember extends Entity { + + private final String iamMember; + + /** Creates a iamMember entity given the iamMember. */ + public IamMember(String iamMember) { + super(Type.IAM_MEMBER); + this.iamMember = iamMember; + } + + /** Returns iamMember. */ + public String getIamMember() { + return iamMember; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + IamMember iam = (IamMember) obj; + return Objects.equals(getType(), iam.getType()) && Objects.equals(iamMember, iam.iamMember); + } + + @Override + public int hashCode() { + return Objects.hash(getType(), iamMember); + } + + @Override + public String toString() { + return toPb().toString(); + } + + @Override + Access toPb() { + return new Access().setIamMember(iamMember); + } + } + private Acl(Entity entity, Role role) { this.entity = checkNotNull(entity); this.role = role; diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Model.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Model.java index abe1f0f2b..64ef0e4a7 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Model.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Model.java @@ -108,6 +108,12 @@ public Builder setLabels(Map labels) { return this; } + @Override + Builder setLocation(String location) { + infoBuilder.setLocation(location); + return this; + } + @Override Builder setTrainingRuns(List trainingRunList) { infoBuilder.setTrainingRuns(trainingRunList); diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelInfo.java index 5796c820f..83603cbd2 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelInfo.java @@ -68,6 +68,7 @@ public Model apply(ModelInfo ModelInfo) { private final Long lastModifiedTime; private final Long expirationTime; private final Labels labels; + private final String location; private final ImmutableList trainingRunList; private final ImmutableList featureColumnList; private final ImmutableList labelColumnList; @@ -97,6 +98,8 @@ public abstract static class Builder { */ public abstract Builder setLabels(Map labels); + abstract Builder setLocation(String location); + public abstract Builder setModelId(ModelId modelId); abstract Builder setEtag(String etag); @@ -130,6 +133,7 @@ static class BuilderImpl extends Builder { private Long lastModifiedTime; private Long expirationTime; private Labels labels = Labels.ZERO; + private String location; private List trainingRunList = Collections.emptyList(); private List labelColumnList = Collections.emptyList(); private List featureColumnList = Collections.emptyList(); @@ -150,6 +154,7 @@ static class BuilderImpl extends Builder { this.labelColumnList = modelInfo.labelColumnList; this.featureColumnList = modelInfo.featureColumnList; this.encryptionConfiguration = modelInfo.encryptionConfiguration; + this.location = modelInfo.location; } BuilderImpl(Model modelPb) { @@ -165,6 +170,7 @@ static class BuilderImpl extends Builder { this.lastModifiedTime = modelPb.getLastModifiedTime(); this.expirationTime = modelPb.getExpirationTime(); this.labels = Labels.fromPb(modelPb.getLabels()); + this.location = modelPb.getLocation(); if (modelPb.getTrainingRuns() != null) { this.trainingRunList = modelPb.getTrainingRuns(); } @@ -236,6 +242,12 @@ public Builder setLabels(Map labels) { return this; } + @Override + Builder setLocation(String location) { + this.location = location; + return this; + } + @Override Builder setTrainingRuns(List trainingRunList) { this.trainingRunList = checkNotNull(trainingRunList); @@ -276,6 +288,7 @@ public ModelInfo build() { this.lastModifiedTime = builder.lastModifiedTime; this.expirationTime = builder.expirationTime; this.labels = builder.labels; + this.location = builder.location; this.trainingRunList = ImmutableList.copyOf(builder.trainingRunList); this.labelColumnList = ImmutableList.copyOf(builder.labelColumnList); this.featureColumnList = ImmutableList.copyOf(builder.featureColumnList); @@ -330,6 +343,11 @@ public Map getLabels() { return labels.userMap(); } + /** Returns a location of the model. */ + public String getLocation() { + return location; + } + /** Returns metadata about each training run iteration. */ @BetaApi public ImmutableList getTrainingRuns() { @@ -368,6 +386,7 @@ public String toString() { .add("lastModifiedTime", lastModifiedTime) .add("expirationTime", expirationTime) .add("labels", labels) + .add("location", location) .add("trainingRuns", trainingRunList) .add("labelColumns", labelColumnList) .add("featureColumns", featureColumnList) @@ -416,6 +435,7 @@ Model toPb() { modelPb.setLastModifiedTime(lastModifiedTime); modelPb.setExpirationTime(expirationTime); modelPb.setLabels(labels.toPb()); + modelPb.setLocation(location); modelPb.setTrainingRuns(trainingRunList); if (labelColumnList != null) { modelPb.setLabelColumns(Lists.transform(labelColumnList, StandardSQLField.TO_PB_FUNCTION)); diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java index 825d653dc..5fc37b98e 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java @@ -163,6 +163,7 @@ static QueryStep fromPb(com.google.api.services.bigquery.model.ExplainQueryStep private final long writeMsMax; private final double writeRatioAvg; private final double writeRatioMax; + private final long slotMs; static final class Builder { @@ -195,6 +196,7 @@ static final class Builder { private long writeMsMax; private double writeRatioAvg; private double writeRatioMax; + private long slotMs; private Builder() {} @@ -343,6 +345,11 @@ Builder setWriteRatioMax(double writeRatioMax) { return this; } + Builder setSlotMs(long slotMs) { + this.slotMs = slotMs; + return this; + } + QueryStage build() { return new QueryStage(this); } @@ -378,6 +385,7 @@ QueryStage build() { writeMsMax = builder.writeMsMax; writeRatioAvg = builder.writeRatioAvg; writeRatioMax = builder.writeRatioMax; + slotMs = builder.slotMs; } /** Returns the number of parallel input segments completed. */ @@ -551,6 +559,11 @@ public double getWriteRatioMax() { return writeRatioMax; } + /** Returns the slot-milliseconds used by the stage. */ + public long getSlotMs() { + return slotMs; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -583,6 +596,7 @@ public String toString() { .add("writeMsMax", writeMsMax) .add("writeRatioAvg", writeRatioAvg) .add("writeRatioMax", writeRatioMax) + .add("slotMs", slotMs) .toString(); } @@ -617,7 +631,8 @@ public final int hashCode() { writeMsAvg, writeMsMax, writeRatioAvg, - writeRatioMax); + writeRatioMax, + slotMs); } @Override @@ -657,7 +672,8 @@ public final boolean equals(Object obj) { && Objects.equals(steps, other.steps) && Objects.equals(name, other.name) && Objects.equals(status, other.status) - && Objects.equals(inputStages, other.inputStages); + && Objects.equals(inputStages, other.inputStages) + && Objects.equals(slotMs, other.slotMs); } static Builder newBuilder() { @@ -694,7 +710,8 @@ ExplainQueryStage toPb() { .setWriteMsAvg(writeMsAvg) .setWriteMsMax(writeMsMax) .setWriteRatioAvg(writeRatioAvg) - .setWriteRatioMax(writeRatioMax); + .setWriteRatioMax(writeRatioMax) + .setSlotMs(slotMs); if (steps != null) { stagePb.setSteps(Lists.transform(steps, QueryStep.TO_PB_FUNCTION)); } @@ -734,6 +751,7 @@ static QueryStage fromPb(com.google.api.services.bigquery.model.ExplainQueryStag builder.setWriteMsMax(stagePb.getWriteMsMax()); builder.setWriteRatioAvg(stagePb.getWriteRatioAvg()); builder.setWriteRatioMax(stagePb.getWriteRatioMax()); + builder.setSlotMs(stagePb.getSlotMs()); return builder.build(); } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetInfoTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetInfoTest.java index 42134d252..da190cf21 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetInfoTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetInfoTest.java @@ -36,6 +36,8 @@ public class DatasetInfoTest { ImmutableList.of( Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER), Acl.of(new Acl.View(TableId.of("project", "dataset", "table")))); + private static final List ACCESS_RULES_IAM_MEMBER = + ImmutableList.of(Acl.of(new Acl.IamMember("allUsers"), Acl.Role.READER)); private static final Map LABELS = ImmutableMap.of( "example-label1", "example-value1", @@ -76,10 +78,15 @@ public class DatasetInfoTest { .setDatasetId(DATASET_ID_COMPLETE) .setAcl(ACCESS_RULES_COMPLETE) .build(); + private static final DatasetInfo DATASET_INFO_COMPLETE_WITH_IAM_MEMBER = + DATASET_INFO.toBuilder().setAcl(ACCESS_RULES_IAM_MEMBER).build(); @Test public void testToBuilder() { compareDatasets(DATASET_INFO, DATASET_INFO.toBuilder().build()); + compareDatasets( + DATASET_INFO_COMPLETE_WITH_IAM_MEMBER, + DATASET_INFO_COMPLETE_WITH_IAM_MEMBER.toBuilder().build()); DatasetInfo datasetInfo = DATASET_INFO .toBuilder() diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelInfoTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelInfoTest.java index 2657ccc44..87fa8bbf5 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelInfoTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelInfoTest.java @@ -33,6 +33,7 @@ public class ModelInfoTest { private static final Long EXPIRATION_TIME = 30L; private static final String DESCRIPTION = "description"; private static final String FRIENDLY_NAME = "friendlyname"; + private static final String LOCATION = "US"; private static final EncryptionConfiguration MODEL_ENCRYPTION_CONFIGURATION = EncryptionConfiguration.newBuilder().setKmsKeyName("KMS_KEY_1").build(); @@ -52,6 +53,7 @@ public class ModelInfoTest { .setFriendlyName(FRIENDLY_NAME) .setTrainingRuns(TRAINING_RUN_LIST) .setEncryptionConfiguration(MODEL_ENCRYPTION_CONFIGURATION) + .setLocation(LOCATION) .build(); @Test @@ -75,6 +77,7 @@ public void testBuilder() { assertEquals(FRIENDLY_NAME, MODEL_INFO.getFriendlyName()); assertEquals(TRAINING_OPTIONS, MODEL_INFO.getTrainingRuns().get(0).getTrainingOptions()); assertEquals(MODEL_ENCRYPTION_CONFIGURATION, MODEL_INFO.getEncryptionConfiguration()); + assertEquals(LOCATION, MODEL_INFO.getLocation()); } @Test @@ -88,6 +91,7 @@ public void testOf() { assertNull(modelInfo.getDescription()); assertNull(modelInfo.getFriendlyName()); assertNull(modelInfo.getEncryptionConfiguration()); + assertNull(modelInfo.getLocation()); assertEquals(modelInfo.getTrainingRuns().isEmpty(), true); assertEquals(modelInfo.getLabelColumns().isEmpty(), true); assertEquals(modelInfo.getFeatureColumns().isEmpty(), true); @@ -113,6 +117,7 @@ private void compareModelInfo(ModelInfo expected, ModelInfo value) { assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.getFriendlyName(), value.getFriendlyName()); assertEquals(expected.getLabels(), value.getLabels()); + assertEquals(expected.getLocation(), value.getLocation()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.getTrainingRuns(), value.getTrainingRuns()); assertEquals(expected.getLabelColumns(), value.getLabelColumns()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryStageTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryStageTest.java index 0c448516d..69edb3988 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryStageTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryStageTest.java @@ -59,6 +59,7 @@ public class QueryStageTest { private static final long WRITE_MS_MAX = 50; private static final double WRITE_RATIO_AVG = 9.9; private static final double WRITE_RATIO_MAX = 10.10; + private static final long SLOTMS = 1522540800000L; private static final QueryStage QUERY_STAGE = QueryStage.newBuilder() .setCompletedParallelInputs(COMPLETED_PARALLEL_INPUTS) @@ -90,6 +91,7 @@ public class QueryStageTest { .setWriteMsMax(WRITE_MS_MAX) .setWriteRatioAvg(WRITE_RATIO_AVG) .setWriteRatioMax(WRITE_RATIO_MAX) + .setSlotMs(SLOTMS) .build(); @Test @@ -112,6 +114,8 @@ public void testBuilder() { assertEquals(INPUT_STAGES, QUERY_STAGE.getInputStages()); assertEquals(PARALLEL_INPUTS, QUERY_STAGE.getParallelInputs()); assertEquals(NAME, QUERY_STAGE.getName()); + assertEquals(READ_MS_AVG, QUERY_STAGE.getReadMsAvg()); + assertEquals(READ_MS_MAX, QUERY_STAGE.getReadMsMax()); assertEquals(READ_RATIO_AVG, QUERY_STAGE.getReadRatioAvg(), 0); assertEquals(READ_RATIO_MAX, QUERY_STAGE.getReadRatioMax(), 0); assertEquals(RECORDS_READ, QUERY_STAGE.getRecordsRead()); @@ -129,6 +133,7 @@ public void testBuilder() { assertEquals(WRITE_MS_MAX, QUERY_STAGE.getWriteMsMax()); assertEquals(WRITE_RATIO_AVG, QUERY_STAGE.getWriteRatioAvg(), 0); assertEquals(WRITE_RATIO_MAX, QUERY_STAGE.getWriteRatioMax(), 0); + assertEquals(SLOTMS, QUERY_STAGE.getSlotMs()); } @Test @@ -178,7 +183,9 @@ private void compareQueryStage(QueryStage expected, QueryStage value) { assertEquals(expected.getWriteMsMax(), expected.getWriteMsMax()); assertEquals(expected.getWriteRatioAvg(), value.getWriteRatioAvg(), 0); assertEquals(expected.getWriteRatioMax(), value.getWriteRatioMax(), 0); + assertEquals(expected.getSlotMs(), value.getSlotMs()); assertEquals(expected.hashCode(), value.hashCode()); + assertEquals(expected.toString(), value.toString()); } private void compareQueryStep(QueryStep expected, QueryStep value) { 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 547c0892e..f2e747319 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 @@ -28,8 +28,11 @@ import static org.junit.Assert.fail; import com.google.api.gax.paging.Page; +import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.Date; import com.google.cloud.RetryOption; +import com.google.cloud.bigquery.Acl; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetField; @@ -375,6 +378,21 @@ public void testGetDataset() { assertNotNull(dataset.getSelfLink()); } + @Test + public void testDatasetUpdateAccess() throws IOException { + Dataset dataset = bigquery.getDataset(DATASET); + ServiceAccountCredentials credentials = + (ServiceAccountCredentials) GoogleCredentials.getApplicationDefault(); + List acl = + ImmutableList.of( + Acl.of(new Acl.Group("projectOwners"), Acl.Role.OWNER), + Acl.of(new Acl.User(credentials.getClientEmail()), Acl.Role.OWNER), + Acl.of(new Acl.IamMember("allUsers"), Acl.Role.READER)); + Dataset remoteDataset = dataset.toBuilder().setAcl(acl).build().update(); + assertNotNull(remoteDataset); + assertEquals(3, remoteDataset.getAcl().size()); + } + @Test public void testGetDatasetWithSelectedFields() { Dataset dataset = diff --git a/pom.xml b/pom.xml index be45ed4e4..f69981aef 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 1.106.0 + 1.107.0 BigQuery Parent https://github.com/googleapis/java-bigquery @@ -63,18 +63,18 @@ UTF-8 github google-cloud-bigquery-parent - 1.92.4 + 1.92.5 1.8.1 1.17.0 1.53.1 - 1.27.0 - 3.11.3 + 1.27.1 + 3.11.4 4.13 28.2-android 1.4.1 1.3.2 1.18 - v2-rev20191211-1.30.3 + v2-rev20191211-1.30.8 @@ -88,12 +88,12 @@ com.google.http-client google-http-client-jackson2 - 1.34.1 + 1.34.2 com.google.http-client google-http-client - 1.34.1 + 1.34.2 com.google.auth @@ -113,7 +113,7 @@ com.google.cloud google-cloud-bigquery - 1.106.0 + 1.107.0 diff --git a/samples/pom.xml b/samples/pom.xml index 4e8991b10..c19ef0131 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -43,7 +43,7 @@ com.google.cloud libraries-bom - 3.5.0 + 4.1.0 pom import @@ -64,7 +64,7 @@ com.google.cloud google-cloud-core - 1.92.4 + 1.92.5 com.google.auth diff --git a/samples/src/main/java/com/example/bigquery/GetTable.java b/samples/src/main/java/com/example/bigquery/GetTable.java new file mode 100644 index 000000000..d9b471631 --- /dev/null +++ b/samples/src/main/java/com/example/bigquery/GetTable.java @@ -0,0 +1,50 @@ +/* + * Copyright 2020 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_get_table] +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Table; +import com.google.cloud.bigquery.TableId; + +public class GetTable { + + public static void runGetTable() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "bigquery_public_data"; + String datasetName = "samples"; + String tableName = "shakespeare"; + getTable(projectId, datasetName, tableName); + } + + public static void getTable(String projectId, String datasetName, String tableName) { + 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(projectId, datasetName, tableName); + Table table = bigquery.getTable(tableId); + System.out.println("Table info: " + table.getDescription()); + } catch (BigQueryException e) { + System.out.println("Table not retrieved. \n" + e.toString()); + } + } +} +// [END bigquery_get_table] diff --git a/samples/src/main/java/com/example/bigquery/ListTables.java b/samples/src/main/java/com/example/bigquery/ListTables.java new file mode 100644 index 000000000..af42c7fc0 --- /dev/null +++ b/samples/src/main/java/com/example/bigquery/ListTables.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020 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_list_tables] +import com.google.api.gax.paging.Page; +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQuery.TableListOption; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.DatasetId; +import com.google.cloud.bigquery.Table; + +public class ListTables { + + public static void runListTables() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "bigquery-public-data"; + String datasetName = "samples"; + listTables(projectId, datasetName); + } + + public static void listTables(String projectId, String datasetName) { + 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(); + + DatasetId datasetId = DatasetId.of(projectId, datasetName); + Page tables = bigquery.listTables(datasetId, TableListOption.pageSize(100)); + tables.iterateAll().forEach(table -> System.out.print(table.getTableId().getTable() + "\n")); + + System.out.println("Tables listed successfully."); + } catch (BigQueryException e) { + System.out.println("Tables were not listed. Error occurred: " + e.toString()); + } + } +} +// [END bigquery_list_tables] diff --git a/samples/src/main/java/com/example/bigquery/LoadTableClustered.java b/samples/src/main/java/com/example/bigquery/LoadTableClustered.java new file mode 100644 index 000000000..7d4987d11 --- /dev/null +++ b/samples/src/main/java/com/example/bigquery/LoadTableClustered.java @@ -0,0 +1,95 @@ +/* + * Copyright 2020 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_load_table_clustered] +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Clustering; +import com.google.cloud.bigquery.Field; +import com.google.cloud.bigquery.FormatOptions; +import com.google.cloud.bigquery.Job; +import com.google.cloud.bigquery.JobInfo; +import com.google.cloud.bigquery.LoadJobConfiguration; +import com.google.cloud.bigquery.Schema; +import com.google.cloud.bigquery.StandardSQLTypeName; +import com.google.cloud.bigquery.TableId; +import com.google.cloud.bigquery.TimePartitioning; +import com.google.common.collect.ImmutableList; + +public class LoadTableClustered { + + public static void runLoadTableClustered() throws Exception { + // TODO(developer): Replace these variables before running the sample. + String datasetName = "MY_DATASET_NAME"; + String tableName = "MY_TABLE_NAME"; + String sourceUri = "/path/to/file.csv"; + loadTableClustered(datasetName, tableName, sourceUri); + } + + public static void loadTableClustered(String datasetName, String tableName, String sourceUri) + throws Exception { + 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); + + Schema schema = + Schema.of( + Field.of("name", StandardSQLTypeName.STRING), + Field.of("post_abbr", StandardSQLTypeName.STRING), + Field.of("date", StandardSQLTypeName.DATE)); + + TimePartitioning partitioning = TimePartitioning.of(TimePartitioning.Type.DAY); + + Clustering clustering = + Clustering.newBuilder().setFields(ImmutableList.of("name", "post_abbr")).build(); + + LoadJobConfiguration loadJobConfig = + LoadJobConfiguration.builder(tableId, sourceUri) + .setFormatOptions(FormatOptions.csv()) + .setSchema(schema) + .setTimePartitioning(partitioning) + .setClustering(clustering) + .build(); + + Job loadJob = bigquery.create(JobInfo.newBuilder(loadJobConfig).build()); + + // Load data from a GCS parquet file into the table + // Blocks until this load table job completes its execution, either failing or succeeding. + Job completedJob = loadJob.waitFor(); + + // Check for errors + if (completedJob == null) { + throw new Exception("Job not executed since it no longer exists."); + } else if (completedJob.getStatus().getError() != null) { + // You can also look at queryJob.getStatus().getExecutionErrors() for all + // errors, not just the latest one. + throw new Exception( + "BigQuery was unable to load into the table due to an error: \n" + + loadJob.getStatus().getError()); + } + System.out.println("Data successfully loaded into clustered table during load job"); + } catch (BigQueryException | InterruptedException e) { + System.out.println("Data not loaded into clustered table during load job \n" + e.toString()); + } + } +} +// [END bigquery_load_table_clustered] diff --git a/samples/src/main/java/com/example/bigquery/UpdateTableExpiration.java b/samples/src/main/java/com/example/bigquery/UpdateTableExpiration.java new file mode 100644 index 000000000..a5d9abedb --- /dev/null +++ b/samples/src/main/java/com/example/bigquery/UpdateTableExpiration.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020 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_update_table_expiration] +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Table; +import java.util.concurrent.TimeUnit; + +public class UpdateTableExpiration { + + public static void runUpdateTableExpiration() { + // TODO(developer): Replace these variables before running the sample. + String datasetName = "MY_DATASET_NAME"; + String tableName = "MY_TABLE_NAME"; + updateTableExpiration(datasetName, tableName); + } + + public static void updateTableExpiration(String datasetName, String tableName) { + 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(); + + // Update table expiration to one day + Long newExpiration = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); + + Table table = bigquery.getTable(datasetName, tableName); + bigquery.update(table.toBuilder().setExpirationTime(newExpiration).build()); + + System.out.println("Table expiration updated successfully to " + newExpiration); + } catch (BigQueryException e) { + System.out.println("Table expiration was not updated \n" + e.toString()); + } + } +} +// [END bigquery_update_table_expiration] diff --git a/samples/src/test/java/com/example/bigquery/GetTableIT.java b/samples/src/test/java/com/example/bigquery/GetTableIT.java new file mode 100644 index 000000000..fafbbadb1 --- /dev/null +++ b/samples/src/test/java/com/example/bigquery/GetTableIT.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020 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 org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class GetTableIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws Exception { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetTable() { + // Get shakespeare table from bigquery-public-data:samples dataset + GetTable.getTable("bigquery-public-data", "samples", "shakespeare"); + assertThat(bout.toString()).contains("Table info:"); + } +} diff --git a/samples/src/test/java/com/example/bigquery/ListDatasetsIT.java b/samples/src/test/java/com/example/bigquery/ListDatasetsIT.java index 6e44e599b..617246ff9 100644 --- a/samples/src/test/java/com/example/bigquery/ListDatasetsIT.java +++ b/samples/src/test/java/com/example/bigquery/ListDatasetsIT.java @@ -41,7 +41,7 @@ public void tearDown() { } @Test - public void listDatasets() { + public void testListDatasets() { // List datasets in bigquery-public-data project ListDatasets.listDatasets("bigquery-public-data"); assertThat(bout.toString()).contains("Success! Dataset ID"); diff --git a/samples/src/test/java/com/example/bigquery/ListTablesIT.java b/samples/src/test/java/com/example/bigquery/ListTablesIT.java new file mode 100644 index 000000000..1892276d9 --- /dev/null +++ b/samples/src/test/java/com/example/bigquery/ListTablesIT.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020 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 org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ListTablesIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws Exception { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testListTables() { + // List tables in bigquery-public-data:samples dataset + ListTables.listTables("bigquery-public-data", "samples"); + assertThat(bout.toString()).contains("Tables listed successfully."); + } +} diff --git a/samples/src/test/java/com/example/bigquery/LoadTableClusteredIT.java b/samples/src/test/java/com/example/bigquery/LoadTableClusteredIT.java new file mode 100644 index 000000000..968235e4b --- /dev/null +++ b/samples/src/test/java/com/example/bigquery/LoadTableClusteredIT.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LoadTableClusteredIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("BIGQUERY_DATASET_NAME"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void loadTableClustered() throws Exception { + String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states-by-date-no-header.csv"; + + String tableName = "LOAD_CLUSTERED_TABLE_TEST"; + + LoadTableClustered.loadTableClustered(BIGQUERY_DATASET_NAME, tableName, sourceUri); + + assertThat(bout.toString()) + .contains("Data successfully loaded into clustered table during load job"); + + // Clean up + DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); + } +} diff --git a/samples/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java b/samples/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java index ed45f2946..60086567a 100644 --- a/samples/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java +++ b/samples/src/test/java/com/example/bigquery/UpdateDatasetAccessIT.java @@ -17,18 +17,33 @@ package com.example.bigquery; import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; public class UpdateDatasetAccessIT { private ByteArrayOutputStream bout; private PrintStream out; + private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + @Before public void setUp() throws Exception { bout = new ByteArrayOutputStream(); @@ -50,5 +65,8 @@ public void updateDatasetAccess() { // Modify dataset's ACL UpdateDatasetAccess.updateDatasetAccess(generatedDatasetName); assertThat(bout.toString()).contains("Dataset Access Control updated successfully"); + + // Clean up + DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, generatedDatasetName); } } diff --git a/samples/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java b/samples/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java index 75bb06e8c..9f9c15c2e 100644 --- a/samples/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java +++ b/samples/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java @@ -17,18 +17,33 @@ package com.example.bigquery; import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; public class UpdateDatasetDescriptionIT { private ByteArrayOutputStream bout; private PrintStream out; + private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + @Before public void setUp() throws Exception { bout = new ByteArrayOutputStream(); @@ -52,5 +67,8 @@ public void updateDatasetDescription() { UpdateDatasetDescription.updateDatasetDescription(generatedDatasetName, newDescription); assertThat(bout.toString()) .contains("Dataset description updated successfully to " + newDescription); + + // Clean up + DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, generatedDatasetName); } } diff --git a/samples/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java b/samples/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java index bd06863dd..7dd4f7f46 100644 --- a/samples/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java +++ b/samples/src/test/java/com/example/bigquery/UpdateDatasetExpirationIT.java @@ -17,18 +17,33 @@ package com.example.bigquery; import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; public class UpdateDatasetExpirationIT { private ByteArrayOutputStream bout; private PrintStream out; + private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + @Before public void setUp() throws Exception { bout = new ByteArrayOutputStream(); @@ -50,5 +65,8 @@ public void updateDatasetExpiration() { // Modify dataset's expiration UpdateDatasetExpiration.updateDatasetExpiration(generatedDatasetName); assertThat(bout.toString()).contains("Dataset description updated successfully"); + + // Clean up + DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, generatedDatasetName); } } diff --git a/samples/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java b/samples/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java new file mode 100644 index 000000000..5352762d8 --- /dev/null +++ b/samples/src/test/java/com/example/bigquery/UpdateTableExpirationIT.java @@ -0,0 +1,68 @@ +/* + * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class UpdateTableExpirationIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("BIGQUERY_DATASET_NAME"); + } + + @Before + public void setUp() throws Exception { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void updateTableExpiration() { + String tableName = "update_expiration_table"; + CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, null); + UpdateTableExpiration.updateTableExpiration(BIGQUERY_DATASET_NAME, tableName); + assertThat(bout.toString()).contains("Table expiration updated successfully"); + + // Clean up + DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); + } +} diff --git a/versions.txt b/versions.txt index 88a349f2b..2d1f4f576 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:1.106.0:1.106.0 \ No newline at end of file +google-cloud-bigquery:1.107.0:1.107.0 \ No newline at end of file