Search in sources :

Example 56 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.

the class AbstractBigtableTable method checkAndMutate.

/**
 * {@inheritDoc}
 */
@Override
public boolean checkAndMutate(final byte[] row, final byte[] family, final byte[] qualifier, final CompareFilter.CompareOp compareOp, final byte[] value, final RowMutations rm) throws IOException {
    LOG.trace("checkAndMutate(byte[], byte[], byte[], CompareOp, byte[], RowMutations)");
    ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withMutations(rm).build();
    return checkAndMutate(row, request, "checkAndMutate");
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)

Example 57 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.

the class TestBigtableAsyncBufferedMutator method testMutateWithList.

@Test
public void testMutateWithList() {
    Put put = new Put(Bytes.toBytes("rowKey"));
    Delete delete = new Delete(Bytes.toBytes("to-be-deleted-row"));
    Append append = new Append(Bytes.toBytes("appended-row"));
    RowMutationEntry rowEntryForPut = RowMutationEntry.create("rowKey");
    RowMutationEntry rowEntryForDelete = RowMutationEntry.create("to-be-deleted-row");
    ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, "appended-row");
    when(mockRequestAdapter.adaptEntry(put)).thenReturn(rowEntryForPut);
    when(mockRequestAdapter.adaptEntry(delete)).thenReturn(rowEntryForDelete);
    when(mockRequestAdapter.adapt(append)).thenReturn(readModifyWriteRow);
    when(mockBulkMutation.add(rowEntryForPut)).thenReturn(ApiFutures.immediateFuture(null));
    when(mockBulkMutation.add(rowEntryForDelete)).thenReturn(ApiFutures.immediateFuture(null));
    when(mockDataClient.readModifyWriteRowAsync(readModifyWriteRow)).thenReturn(ApiFutures.immediateFuture(Result.EMPTY_RESULT));
    asyncBufferedMutator.mutate(Arrays.asList(put, delete, append)).forEach(future -> {
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new AssertionError("BigtableAsyncBufferedMutator#mutate test failed");
        }
    });
    verify(mockRequestAdapter).adaptEntry(put);
    verify(mockRequestAdapter).adaptEntry(delete);
    verify(mockRequestAdapter).adapt(append);
    verify(mockBulkMutation).add(rowEntryForPut);
    verify(mockBulkMutation).add(rowEntryForDelete);
    verify(mockDataClient).readModifyWriteRowAsync(readModifyWriteRow);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) ExecutionException(java.util.concurrent.ExecutionException) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 58 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.

the class SimpleIT method testConnection.

@Test
public void testConnection() throws Exception {
    String projectId = "fake-project";
    String instanceId = "fake-instance";
    String tableId = "myTable";
    String family = "cf";
    String key = "key";
    String value = "value";
    BigtableOptions opts = new BigtableOptions.Builder().setUserAgent("fake").setProjectId(projectId).setInstanceId(instanceId).build();
    try (BigtableSession session = new BigtableSession(opts)) {
        IBigtableTableAdminClient tableAdminClient = session.getTableAdminClientWrapper();
        tableAdminClient.createTable(CreateTableRequest.of(tableId).addFamily(family));
        IBigtableDataClient dataClient = session.getDataClientWrapper();
        dataClient.mutateRow(RowMutation.create(tableId, key).setCell(family, "", value));
        List<Row> results = dataClient.readRowsAsync(Query.create(tableId).rowKey(key)).get();
        Assert.assertEquals(ByteString.copyFromUtf8(value), results.get(0).getCells().get(0).getValue());
    }
}
Also used : IBigtableTableAdminClient(com.google.cloud.bigtable.core.IBigtableTableAdminClient) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) IBigtableDataClient(com.google.cloud.bigtable.core.IBigtableDataClient) ByteString(com.google.protobuf.ByteString) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 59 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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());
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) SetCell(com.google.bigtable.v2.Mutation.SetCell) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 60 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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());
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) SetCell(com.google.bigtable.v2.Mutation.SetCell) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4