From eb459f400ee37cf9850e31471687efb143c2df17 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Wed, 6 Feb 2019 22:53:24 -0500 Subject: [PATCH 1/5] Adding Cloud Bigtable Mutation fromProto --- .../google/cloud/bigtable/data/v2/models/Mutation.java | 10 ++++++++++ .../cloud/bigtable/data/v2/models/MutationTest.java | 2 ++ 2 files changed, 12 insertions(+) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java index 9664a7e7d5d9..475c75a14186 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java @@ -62,6 +62,16 @@ public static Mutation create() { return new Mutation(false); } + /** + * Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. + * + */ + public static Mutation fromProto(List protos) { + Mutation mutation = new Mutation(false); + mutation.mutations.addAll(protos); + return mutation; + } + /** * Creates new instance of Mutation object which allows setCell operation to use server side * timestamp. This is dangerous because mutations will no longer be idempotent, which might cause diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java index ccbc28be0e2d..b3525a509458 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java @@ -95,6 +95,8 @@ public void setCellTest() { assertThat(actual.get(3).getSetCell().getValue()) .isEqualTo(ByteString.copyFromUtf8("fake-value2")); assertThat(actual.get(3).getSetCell().getTimestampMicros()).isIn(expectedTimestampRange); + + assertThat(Mutation.fromProto(actual).getMutations()).isEqualTo(actual); } @Test From 6b7b9ef5b974f506a56768dd24c425930adb740f Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Thu, 7 Feb 2019 08:30:03 -0500 Subject: [PATCH 2/5] Fixing formatting --- .../com/google/cloud/bigtable/data/v2/models/Mutation.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java index 475c75a14186..94085027118f 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java @@ -62,11 +62,8 @@ public static Mutation create() { return new Mutation(false); } - /** - * Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. - * - */ - public static Mutation fromProto(List protos) { + /** Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. */ + public static Mutation fromProto(List protos) { Mutation mutation = new Mutation(false); mutation.mutations.addAll(protos); return mutation; From 8ab3baa7af1396b315c733f51140c28b158982f5 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Thu, 7 Feb 2019 17:45:53 -0500 Subject: [PATCH 3/5] Addressing comments `fromProto` becomes `fromProtoUnsafe` --- .../cloud/bigtable/data/v2/models/Mutation.java | 16 +++++++++------- .../bigtable/data/v2/models/MutationTest.java | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java index 94085027118f..fa282e0a1ffb 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java @@ -62,13 +62,6 @@ public static Mutation create() { return new Mutation(false); } - /** Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. */ - public static Mutation fromProto(List protos) { - Mutation mutation = new Mutation(false); - mutation.mutations.addAll(protos); - return mutation; - } - /** * Creates new instance of Mutation object which allows setCell operation to use server side * timestamp. This is dangerous because mutations will no longer be idempotent, which might cause @@ -80,6 +73,15 @@ public static Mutation createUnsafe() { return new Mutation(true); } + + /** Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. */ + @BetaApi + public static Mutation fromProtoUnsafe(List protos) { + Mutation mutation = new Mutation(true); + mutation.mutations.addAll(protos); + return mutation; + } + private Mutation(boolean allowServersideTimestamp) { this.allowServersideTimestamp = allowServersideTimestamp; } diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java index b3525a509458..5857a79e159a 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java @@ -96,7 +96,7 @@ public void setCellTest() { .isEqualTo(ByteString.copyFromUtf8("fake-value2")); assertThat(actual.get(3).getSetCell().getTimestampMicros()).isIn(expectedTimestampRange); - assertThat(Mutation.fromProto(actual).getMutations()).isEqualTo(actual); + assertThat(Mutation.fromProtoUnsafe(actual).getMutations()).isEqualTo(actual); } @Test From 7254346d744a3225a543e7077f9a96b2d5588b37 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Thu, 7 Feb 2019 18:36:46 -0500 Subject: [PATCH 4/5] Fixing lint issues. --- .../java/com/google/cloud/bigtable/data/v2/models/Mutation.java | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java index fa282e0a1ffb..0f8c97c0ab39 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java @@ -73,7 +73,6 @@ public static Mutation createUnsafe() { return new Mutation(true); } - /** Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. */ @BetaApi public static Mutation fromProtoUnsafe(List protos) { From 8951d3bd9b387040f312562e94b31f8f091633ac Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Thu, 7 Feb 2019 18:48:52 -0500 Subject: [PATCH 5/5] adding a warning to `fromProtoUnsafe` --- .../com/google/cloud/bigtable/data/v2/models/Mutation.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java index 0f8c97c0ab39..5c1372ad76e9 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java @@ -73,7 +73,12 @@ public static Mutation createUnsafe() { return new Mutation(true); } - /** Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. */ + /** + * Wraps the List of protobuf {@link com.google.bigtable.v2.Mutation}. This methods, like {@link + * #createUnsafe()}, allows setCell operation to use server side timestamp. This is dangerous + * because mutations will no longer be idempotent, which might cause multiple duplicate values to + * be stored in Bigtable. This option should only be used for advanced usecases with extreme care. + */ @BetaApi public static Mutation fromProtoUnsafe(List protos) { Mutation mutation = new Mutation(true);