use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createBulkReadRowsCallable.
/**
* Creates a callable chain to handle bulk ReadRows RPCs. This is meant to be used in ReadRows
* batcher. The chain will:
*
* <ul>
* <li>Convert a {@link Query} into a {@link com.google.bigtable.v2.ReadRowsRequest}.
* <li>Upon receiving the response stream, it will merge the {@link
* com.google.bigtable.v2.ReadRowsResponse.CellChunk}s in logical rows. The actual row
* implementation can be configured in by the {@code rowAdapter} parameter.
* <li>Retry/resume on failure.
* <li>Filter out marker rows.
* <li>Construct a {@link UnaryCallable} that will buffer the entire stream into memory before
* completing. If the stream is empty, then the list will be empty.
* <li>Add tracing & metrics.
* </ul>
*/
private <RowT> UnaryCallable<Query, List<RowT>> createBulkReadRowsCallable(RowAdapter<RowT> rowAdapter) {
ServerStreamingCallable<ReadRowsRequest, RowT> readRowsCallable = createReadRowsBaseCallable(settings.readRowsSettings(), rowAdapter);
ServerStreamingCallable<Query, RowT> readRowsUserCallable = new ReadRowsUserCallable<>(readRowsCallable, requestContext);
SpanName span = getSpanName("ReadRows");
// The TracedBatcherUnaryCallable has to be wrapped by the TracedUnaryCallable, so that
// TracedUnaryCallable can inject a tracer for the TracedBatcherUnaryCallable to interact with
UnaryCallable<Query, List<RowT>> tracedBatcher = new TracedBatcherUnaryCallable<>(readRowsUserCallable.all());
UnaryCallable<Query, List<RowT>> withHeaderTracer = new HeaderTracerUnaryCallable(tracedBatcher);
UnaryCallable<Query, List<RowT>> traced = new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), span);
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}
use of com.google.cloud.bigtable.data.v2.models.Query 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.Query in project java-bigtable by googleapis.
the class Reads method readPrefix.
public static void readPrefix(String projectId, String instanceId, String tableId) {
// the "close" method on the client to safely clean up any remaining background resources.
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
Query query = Query.create(tableId).prefix("phone");
ServerStream<Row> rows = dataClient.readRows(query);
for (Row row : rows) {
printRow(row);
}
} catch (IOException e) {
System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.models.Query in project native-image-support-java by GoogleCloudPlatform.
the class BigTableSampleApplication method readData.
private static void readData(BigtableDataClient client, String tableId) {
Query query = Query.create(tableId).prefix("");
ServerStream<Row> rows = client.readRows(query);
System.out.println("Reading phone data in table: ");
for (Row row : rows) {
System.out.println("Key: " + row.getKey().toStringUtf8());
for (RowCell cell : row.getCells()) {
System.out.printf("\t%s: %s @%s%n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
}
System.out.println();
}
}
Aggregations