Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable: Add createUnsafe factory method in Mutation model #3800

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,29 @@ public final class Mutation implements MutationApi<Mutation>, Serializable {
@InternalApi("Visible for testing")
static final int MAX_BYTE_SIZE = 200 * 1024 * 1024;

private final boolean allowServersideTimestamp;

private transient ImmutableList.Builder<com.google.bigtable.v2.Mutation> mutations =
ImmutableList.builder();

private int numMutations;
private long byteSize;

public static Mutation create() {
return new Mutation();
return new Mutation(false);
}

private Mutation() {}
/**
* Creates Mutation object which allows setCell operation to set server side timestamp.

This comment was marked as spam.

This comment was marked as spam.

* @return Mutation object.
*/
public static Mutation createUnsafe() {
return new Mutation(true);
}

private Mutation(boolean allowServersideTimestamp) {
this.allowServersideTimestamp = allowServersideTimestamp;
}

private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
input.defaultReadObject();
Expand Down Expand Up @@ -102,7 +114,9 @@ public Mutation setCell(
Validations.validateFamily(familyName);
Preconditions.checkNotNull(qualifier, "qualifier can't be null.");
Preconditions.checkNotNull(value, "value can't be null.");
Preconditions.checkArgument(timestamp != -1, "Serverside timestamps are not supported");
if (!allowServersideTimestamp) {
Preconditions.checkArgument(timestamp != -1, "Serverside timestamps are not supported");

This comment was marked as spam.

}

addMutation(
com.google.bigtable.v2.Mutation.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public void setCellTest() {
assertThat(actual.get(3).getSetCell().getTimestampMicros()).isIn(expectedTimestampRange);
}

@Test
public void setCellWithServerSideTimestamp() {
Mutation mutation = Mutation.createUnsafe();
mutation
.setCell(
"fake-family",
ByteString.copyFromUtf8("fake-qualifier"),
-1,

This comment was marked as spam.

ByteString.copyFromUtf8("fake-value"));
List<com.google.bigtable.v2.Mutation> actual = mutation.getMutations();
assertThat(actual.get(0).getSetCell().getTimestampMicros()).isEqualTo(-1);
}

@Test
public void deleteColumnTest() {
mutation
Expand Down