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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations