Search in sources :

Example 71 with Row

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

the class BigtableDataClient method existsAsync.

/**
 * Confirms asynchronously if given row key exists or not.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
 *   String tableId = "[TABLE]";
 *   final ByteString key = ByteString.copyFromUtf8("key");
 *
 *   ApiFuture<Boolean> futureResult = bigtableDataClient.existsAsync(tableId, key);
 *
 *   ApiFutures.addCallback(futureResult, new ApiFutureCallback<Boolean>() {
 *     public void onFailure(Throwable t) {
 *       t.printStackTrace();
 *     }
 *     public void onSuccess(Boolean isRowPresent) {
 *       if(isRowPresent) {
 *         System.out.println(key.toStringUtf8() + " is present");
 *       }
 *     }
 *   }, MoreExecutors.directExecutor());
 * }
 * }</pre>
 */
public ApiFuture<Boolean> existsAsync(String tableId, ByteString rowKey) {
    Query query = Query.create(tableId).rowKey(rowKey).filter(FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip()));
    ApiFuture<Row> resultFuture = stub.readRowCallable().futureCall(query);
    return ApiFutures.transform(resultFuture, new ApiFunction<Row, Boolean>() {

        @Override
        public Boolean apply(Row row) {
            return row != null;
        }
    }, MoreExecutors.directExecutor());
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)

Example 72 with Row

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

the class FilterMarkerRowsCallableTest method testRealRow.

@Test
public void testRealRow() {
    Row row = buildRealRow();
    ServerStreamingStashCallable<ReadRowsRequest, Row> innerCallable = new ServerStreamingStashCallable<>(Lists.newArrayList(row));
    FilterMarkerRowsCallable<Row> filterCallable = new FilterMarkerRowsCallable<>(innerCallable, rowAdapter);
    ServerStream<Row> results = filterCallable.call(ReadRowsRequest.getDefaultInstance());
    assertThat(results).containsExactly(row);
}
Also used : ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 73 with Row

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

the class FilterMarkerRowsCallableTest method testMixed.

@Test
public void testMixed() {
    Row row = buildRealRow();
    Row markerRow = buildScanMarker();
    ServerStreamingStashCallable<ReadRowsRequest, Row> innerCallable = new ServerStreamingStashCallable<>(Lists.newArrayList(row, markerRow));
    FilterMarkerRowsCallable<Row> filterCallable = new FilterMarkerRowsCallable<>(innerCallable, rowAdapter);
    ServerStream<Row> results = filterCallable.call(ReadRowsRequest.getDefaultInstance());
    assertThat(results).containsExactly(row);
}
Also used : ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 74 with Row

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

the class BigtableDataClientTests method readRowStrTest.

@Test
public void readRowStrTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key"))).thenReturn(ApiFutures.immediateFuture(expectedRow));
    Row actualRow = bigtableDataClient.readRow("fake-table", "fake-row-key");
    assertThat(actualRow).isEqualTo(expectedRow);
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 75 with Row

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

the class BigtableDataClientTests method readRowTest.

@Test
public void readRowTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key"))).thenReturn(ApiFutures.immediateFuture(expectedRow));
    Row actualRow = bigtableDataClient.readRow("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(actualRow).isEqualTo(expectedRow);
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) 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