Search in sources :

Example 81 with Row

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

the class CheckAndMutateIT method test.

@Test
public void test() throws Exception {
    String tableId = testEnvRule.env().getTableId();
    String familyId = testEnvRule.env().getFamilyId();
    String rowKey = UUID.randomUUID().toString();
    testEnvRule.env().getDataClient().mutateRowCallable().call(RowMutation.create(tableId, rowKey).setCell(familyId, "q1", "val1").setCell(familyId, "q2", "val2"));
    testEnvRule.env().getDataClient().checkAndMutateRowAsync(ConditionalRowMutation.create(tableId, rowKey).condition(FILTERS.qualifier().exactMatch("q1")).then(Mutation.create().setCell(familyId, "q3", "q1"))).get(1, TimeUnit.MINUTES);
    Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(tableId).rowKey(rowKey));
    assertThat(row.getCells()).hasSize(3);
    assertThat(row.getCells().get(2).getValue()).isEqualTo(ByteString.copyFromUtf8("q1"));
}
Also used : ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 82 with Row

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

the class LargeRowIT method testWriteRead.

@Test
public void testWriteRead() throws Exception {
    String rowKey = UUID.randomUUID().toString();
    String familyId = testEnvRule.env().getFamilyId();
    byte[] largeValueBytes = new byte[100 * 1024 * 1024];
    Random random = new Random();
    random.nextBytes(largeValueBytes);
    ByteString largeValue = ByteString.copyFrom(largeValueBytes);
    // Create a 200 MB row
    logger.info("Sending large row, this will take awhile");
    for (int i = 0; i < 2; i++) {
        testEnvRule.env().getDataClient().mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowKey).setCell(familyId, ByteString.copyFromUtf8("q" + i), largeValue)).get(10, TimeUnit.MINUTES);
    }
    logger.info("Reading large row, this will take awhile");
    // Read it back
    Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowKey));
    assertThat(row.getCells()).hasSize(2);
    assertThat(row.getCells().get(0).getValue()).isEqualTo(largeValue);
    assertThat(row.getCells().get(1).getValue()).isEqualTo(largeValue);
}
Also used : Random(java.util.Random) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 83 with Row

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

the class ReadIT method read.

@Test
public void read() throws Throwable {
    int numRows = 5;
    List<Row> expectedRows = Lists.newArrayList();
    String uniqueKey = prefix + "-read";
    long timestampMicros = System.currentTimeMillis() * 1_000;
    for (int i = 0; i < numRows; i++) {
        testEnvRule.env().getDataClient().mutateRowCallable().call(RowMutation.create(testEnvRule.env().getTableId(), uniqueKey + "-" + i).setCell(testEnvRule.env().getFamilyId(), "q", timestampMicros, "my-value"));
        expectedRows.add(Row.create(ByteString.copyFromUtf8(uniqueKey + "-" + i), ImmutableList.of(RowCell.create(testEnvRule.env().getFamilyId(), ByteString.copyFromUtf8("q"), timestampMicros, ImmutableList.<String>of(), ByteString.copyFromUtf8("my-value")))));
    }
    String tableId = testEnvRule.env().getTableId();
    // Sync
    Query query = Query.create(tableId).range(uniqueKey + "-0", uniqueKey + "-" + numRows);
    ArrayList<Row> actualResults = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
    assertThat(actualResults).containsExactlyElementsIn(expectedRows);
    // Async
    AccumulatingObserver observer = new AccumulatingObserver();
    testEnvRule.env().getDataClient().readRowsAsync(query, observer);
    observer.awaitCompletion();
    assertThat(observer.responses).containsExactlyElementsIn(expectedRows);
    // Point Sync
    Row actualRow = testEnvRule.env().getDataClient().readRow(tableId, expectedRows.get(0).getKey());
    assertThat(actualRow).isEqualTo(expectedRows.get(0));
    // Point Async
    ApiFuture<Row> actualRowFuture = testEnvRule.env().getDataClient().readRowAsync(tableId, expectedRows.get(0).getKey());
    assertThat(actualRowFuture.get()).isEqualTo(expectedRows.get(0));
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 84 with Row

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

the class ReadIT method readSingleNonexistentAsyncCallback.

@Test
public void readSingleNonexistentAsyncCallback() throws Exception {
    ApiFuture<Row> future = testEnvRule.env().getDataClient().readRowAsync(testEnvRule.env().getTableId(), "somenonexistentkey");
    final AtomicReference<Throwable> unexpectedError = new AtomicReference<>();
    final AtomicBoolean found = new AtomicBoolean();
    final CountDownLatch latch = new CountDownLatch(1);
    ApiFutures.addCallback(future, new ApiFutureCallback<Row>() {

        @Override
        public void onFailure(Throwable t) {
            unexpectedError.set(t);
            latch.countDown();
        }

        @Override
        public void onSuccess(Row result) {
            found.set(true);
            latch.countDown();
        }
    }, MoreExecutors.directExecutor());
    latch.await(1, TimeUnit.MINUTES);
    if (unexpectedError.get() != null) {
        throw new RuntimeException("Unexpected async error", unexpectedError.get());
    }
    assertThat(found.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Row(com.google.cloud.bigtable.data.v2.models.Row) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 85 with Row

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

the class ReadIT method readEmpty.

@Test
public void readEmpty() throws Throwable {
    String uniqueKey = prefix + "-readEmpty";
    Query query = Query.create(testEnvRule.env().getTableId()).rowKey(uniqueKey);
    // Sync
    ArrayList<Row> rows = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
    assertThat(rows).isEmpty();
    // Async
    AccumulatingObserver observer = new AccumulatingObserver();
    testEnvRule.env().getDataClient().readRowsAsync(query, observer);
    observer.awaitCompletion();
    assertThat(observer.responses).isEmpty();
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) 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