use of com.google.spanner.v1.Mutation in project java-bigtable-hbase by googleapis.
the class TestPutAdapter method testMultipleCellsInOneFamilyAreConverted.
@Test
public void testMultipleCellsInOneFamilyAreConverted() {
byte[] row = dataHelper.randomData("rk-");
byte[] family = dataHelper.randomData("f1");
byte[] qualifier1 = dataHelper.randomData("qual1");
byte[] qualifier2 = dataHelper.randomData("qual2");
byte[] value1 = dataHelper.randomData("v1");
byte[] value2 = dataHelper.randomData("v2");
long timestamp1 = 1L;
long timestamp2 = 2L;
Put hbasePut = new Put(row);
hbasePut.addColumn(family, qualifier1, timestamp1, value1);
hbasePut.addColumn(family, qualifier2, timestamp2, value2);
MutateRowRequest request = adapt(hbasePut);
Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
Assert.assertEquals(2, request.getMutationsCount());
Mutation mutation = request.getMutations(0);
Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
SetCell setCell = mutation.getSetCell();
Assert.assertArrayEquals(family, setCell.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier1, setCell.getColumnQualifier().toByteArray());
Assert.assertEquals(TimeUnit.MILLISECONDS.toMicros(timestamp1), setCell.getTimestampMicros());
Assert.assertArrayEquals(value1, setCell.getValue().toByteArray());
Mutation mod2 = request.getMutations(1);
SetCell setCell2 = mod2.getSetCell();
Assert.assertArrayEquals(family, setCell2.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier2, setCell2.getColumnQualifier().toByteArray());
Assert.assertEquals(TimeUnit.MILLISECONDS.toMicros(timestamp2), setCell2.getTimestampMicros());
Assert.assertArrayEquals(value2, setCell2.getValue().toByteArray());
}
use of com.google.spanner.v1.Mutation in project java-bigtable-hbase by googleapis.
the class TestPutAdapter method testUnsetTimestampsAreNotPopulated.
@Test
public void testUnsetTimestampsAreNotPopulated() {
PutAdapter adapter = new PutAdapter(-1, false);
byte[] row = dataHelper.randomData("rk-");
byte[] family1 = dataHelper.randomData("f1");
byte[] qualifier1 = dataHelper.randomData("qual1");
byte[] value1 = dataHelper.randomData("v1");
Put hbasePut = new Put(row).addColumn(family1, qualifier1, value1);
com.google.cloud.bigtable.data.v2.models.Mutation unsafeMutation = com.google.cloud.bigtable.data.v2.models.Mutation.createUnsafe();
adapter.adapt(hbasePut, unsafeMutation);
RowMutation rowMutation = RowMutation.create(TABLE_ID, ByteString.copyFrom(hbasePut.getRow()), unsafeMutation);
MutateRowRequest request = rowMutation.toProto(REQUEST_CONTEXT);
Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
Assert.assertEquals(1, request.getMutationsCount());
Mutation mutation = request.getMutations(0);
Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
SetCell setCell = mutation.getSetCell();
Assert.assertArrayEquals(family1, setCell.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier1, setCell.getColumnQualifier().toByteArray());
Assert.assertEquals(-1, setCell.getTimestampMicros());
Assert.assertArrayEquals(value1, setCell.getValue().toByteArray());
}
use of com.google.spanner.v1.Mutation in project java-bigtable-hbase by googleapis.
the class TestCheckAndMutateUtil method testDelete.
@Test
public /**
* Tests that a CheckAndMutate with a {@link Delete} works correctly for the filter and mutation
* aspects
*/
void testDelete() throws DoNotRetryIOException {
CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(CompareOp.EQUAL, checkValue).withDelete(new Delete(rowKey).addColumns(family, qual)).build().toProto(REQUEST_CONTEXT);
Assert.assertEquals(1, result.getTrueMutationsCount());
Mutation.DeleteFromColumn delete = result.getTrueMutations(0).getDeleteFromColumn();
Assert.assertArrayEquals(family, delete.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qual, delete.getColumnQualifier().toByteArray());
checkPredicate(result);
}
use of com.google.spanner.v1.Mutation in project pgadapter by GoogleCloudPlatform.
the class MutationWriterTest method testWritePartials.
@Test
public void testWritePartials() throws Exception {
Map<String, TypeCode> tableColumns = ImmutableMap.of("number", TypeCode.INT64, "name", TypeCode.STRING);
CSVFormat format = CSVFormat.POSTGRESQL_TEXT.builder().setHeader(tableColumns.keySet().toArray(new String[0])).build();
Connection connection = mock(Connection.class);
DatabaseClient databaseClient = mock(DatabaseClient.class);
MutationWriter mutationWriter = new MutationWriter(CopyTransactionMode.ImplicitNonAtomic, connection, databaseClient, "numbers", tableColumns, /* indexedColumnsCount = */
1, format, false);
mutationWriter.addCopyData("1\t\"One\"\n2\t\"Two\"\n3\t\"Three\"\n4\t\"Four\"\n5\t\"Five\"\n".getBytes(StandardCharsets.UTF_8));
mutationWriter.close();
ExecutorService executor = Executors.newFixedThreadPool(2);
executor.submit(() -> {
mutationWriter.addCopyData("1\t\"One\"\n".getBytes(StandardCharsets.UTF_8));
mutationWriter.addCopyData("2\t\"Two".getBytes(StandardCharsets.UTF_8));
mutationWriter.addCopyData("\"".getBytes(StandardCharsets.UTF_8));
mutationWriter.addCopyData("\n3\t".getBytes(StandardCharsets.UTF_8));
mutationWriter.addCopyData("\"Three\"\n4\t\"Four\"\n5\t".getBytes(StandardCharsets.UTF_8));
mutationWriter.addCopyData("\"Five\"\n".getBytes(StandardCharsets.UTF_8));
mutationWriter.close();
return null;
});
Future<Long> updateCount = executor.submit(mutationWriter);
assertEquals(5L, updateCount.get().longValue());
List<Mutation> expectedMutations = ImmutableList.of(Mutation.newInsertBuilder("numbers").set("number").to(1L).set("name").to("One").build(), Mutation.newInsertBuilder("numbers").set("number").to(2L).set("name").to("Two").build(), Mutation.newInsertBuilder("numbers").set("number").to(3L).set("name").to("Three").build(), Mutation.newInsertBuilder("numbers").set("number").to(4L).set("name").to("Four").build(), Mutation.newInsertBuilder("numbers").set("number").to(5L).set("name").to("Five").build());
verify(databaseClient).write(expectedMutations);
executor.shutdown();
}
use of com.google.spanner.v1.Mutation in project pgadapter by GoogleCloudPlatform.
the class MutationWriterTest method testWriteMutations.
@Test
public void testWriteMutations() throws Exception {
Map<String, TypeCode> tableColumns = ImmutableMap.of("number", TypeCode.INT64, "name", TypeCode.STRING);
CSVFormat format = CSVFormat.POSTGRESQL_TEXT.builder().setHeader(tableColumns.keySet().toArray(new String[0])).build();
Connection connection = mock(Connection.class);
DatabaseClient databaseClient = mock(DatabaseClient.class);
MutationWriter mutationWriter = new MutationWriter(CopyTransactionMode.ImplicitAtomic, connection, databaseClient, "numbers", tableColumns, /* indexedColumnsCount = */
1, format, false);
mutationWriter.addCopyData("1\t\"One\"\n2\t\"Two\"\n".getBytes(StandardCharsets.UTF_8));
mutationWriter.close();
long updateCount = mutationWriter.call();
assertEquals(2L, updateCount);
List<Mutation> expectedMutations = ImmutableList.of(Mutation.newInsertBuilder("numbers").set("number").to(1L).set("name").to("One").build(), Mutation.newInsertBuilder("numbers").set("number").to(2L).set("name").to("Two").build());
verify(databaseClient).write(expectedMutations);
}
Aggregations