use of com.google.spanner.v1.Mutation in project DataflowTemplates by GoogleCloudPlatform.
the class BeamRowToBigtableFnTest method processElementWithCompoundKey.
@Test
public void processElementWithCompoundKey() {
String columnFamily = "default";
boolean rowKeyValue1 = false;
String rowKeyColumnName1 = "rowkey1";
Long rowKeyValue2 = Long.MAX_VALUE;
String rowKeyColumnName2 = "rowkey2";
String stringValue = "hello this is a random string";
String stringColumnName = "stringColumn";
Schema schema = Schema.builder().addField(Schema.Field.of(rowKeyColumnName1, FieldType.BOOLEAN.withMetadata(CassandraRowMapperFn.KEY_ORDER_METADATA_KEY, "0"))).addField(Schema.Field.of(rowKeyColumnName2, FieldType.INT64.withMetadata(CassandraRowMapperFn.KEY_ORDER_METADATA_KEY, "1"))).addStringField(stringColumnName).build();
Row input = Row.withSchema(schema).addValue(rowKeyValue1).addValue(rowKeyValue2).addValue(stringValue).build();
final List<Row> rows = Collections.singletonList(input);
List<Mutation> mutations = new ArrayList<>();
mutations.add(createMutation(columnFamily, stringColumnName, ByteString.copyFrom(Bytes.toBytes(stringValue))));
final List<KV<ByteString, Iterable<Mutation>>> expectedBigtableRows = ImmutableList.of(KV.of(ByteString.copyFrom(Bytes.toBytes("false#9223372036854775807")), mutations));
PCollection<KV<ByteString, Iterable<Mutation>>> bigtableRows = pipeline.apply("Create", Create.of(rows)).apply("Transform to Bigtable", ParDo.of(BeamRowToBigtableFn.create(ValueProvider.StaticValueProvider.of("#"), ValueProvider.StaticValueProvider.of("default"))));
PAssert.that(bigtableRows).containsInAnyOrder(expectedBigtableRows);
pipeline.run();
}
use of com.google.spanner.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteCellsFromColumn.
@Test
public void testDeleteCellsFromColumn() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteCellsFromColumn("family", "qualifier", Optional.empty(), Optional.empty()).deleteCellsFromColumn("family", "qualifier", Optional.of(100L), Optional.of(999L));
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(2, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_COLUMN, mutation.getMutationCase());
assertEquals("family", mutation.getDeleteFromColumn().getFamilyName());
assertEquals("qualifier", mutation.getDeleteFromColumn().getColumnQualifier().toStringUtf8());
assertEquals(TimestampRange.getDefaultInstance(), mutation.getDeleteFromColumn().getTimeRange());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(1);
assertEquals(Mutation.MutationCase.DELETE_FROM_COLUMN, mutation.getMutationCase());
assertEquals("family", mutation.getDeleteFromColumn().getFamilyName());
assertEquals("qualifier", mutation.getDeleteFromColumn().getColumnQualifier().toStringUtf8());
assertEquals(100L, mutation.getDeleteFromColumn().getTimeRange().getStartTimestampMicros());
assertEquals(999L, mutation.getDeleteFromColumn().getTimeRange().getEndTimestampMicros());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.google.spanner.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteColumnFamily.
@Test
public void testDeleteColumnFamily() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteColumnFamily("family");
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_FAMILY, mutation.getMutationCase());
assertEquals("family", mutation.getDeleteFromFamily().getFamilyName());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromColumn.getDefaultInstance(), mutation.getDeleteFromColumn());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.google.spanner.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testWriteColumnAndTimestamp.
@Test
public void testWriteColumnAndTimestamp() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.write("family:qualifier", ByteString.copyFromUtf8("value"), 100L).write("family", "qualifier", ByteString.copyFromUtf8("value"), 100L);
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(2, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
for (Mutation mutation : bigtableMutationImpl.getMutateRowRequest().getMutationsList()) {
assertEquals(Mutation.MutationCase.SET_CELL, mutation.getMutationCase());
assertEquals("family", mutation.getSetCell().getFamilyName());
assertEquals("qualifier", mutation.getSetCell().getColumnQualifier().toStringUtf8());
assertEquals("value", mutation.getSetCell().getValue().toStringUtf8());
assertEquals(100L, mutation.getSetCell().getTimestampMicros());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.DeleteFromColumn.getDefaultInstance(), mutation.getDeleteFromColumn());
}
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
use of com.google.spanner.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteColumnFamilyAndQualifier.
@Test
public void testDeleteColumnFamilyAndQualifier() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteColumn("family", "qualifier");
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_COLUMN, mutation.getMutationCase());
assertEquals("family", mutation.getDeleteFromColumn().getFamilyName());
assertEquals("qualifier", mutation.getDeleteFromColumn().getColumnQualifier().toStringUtf8());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
Aggregations