Skip to content

Commit

Permalink
Adding Cloud Bigtable Mutation fromProto (#4461)
Browse files Browse the repository at this point in the history
* Adding Cloud Bigtable Mutation fromProto

* Fixing formatting

* Addressing comments
`fromProto` becomes `fromProtoUnsafe`

* Fixing lint issues.

* adding a warning to `fromProtoUnsafe`
  • Loading branch information
sduskis authored Feb 8, 2019
1 parent 81bdd00 commit 1baa602
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ public static Mutation createUnsafe() {
return new Mutation(true);
}

/**
* 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<com.google.bigtable.v2.Mutation> protos) {
Mutation mutation = new Mutation(true);
mutation.mutations.addAll(protos);
return mutation;
}

private Mutation(boolean allowServersideTimestamp) {
this.allowServersideTimestamp = allowServersideTimestamp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.fromProtoUnsafe(actual).getMutations()).isEqualTo(actual);
}

@Test
Expand Down

0 comments on commit 1baa602

Please sign in to comment.