public class BigtableDataClient extends Object implements AutoCloseable
This class provides the ability to make remote calls to the backing service. Sample code to get started:
// One instance per application.
BigtableDataClient client = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")
for(Row row : client.readRows(Query.create("[TABLE]"))) {
// Do something with row
}
// Cleanup during application shutdown.
client.close();
Creating a new client is a very expensive operation and should only be done once and shared in an application. However, close() needs to be called on the client object to clean up resources such as threads during application shutdown.
This client can be safely shared across multiple threads except for the Batcher instances returned from bulk operations, eg. `newBulkMutationBatcher()`, `newBulkReadRowsBatcher()`.
The surface of this class includes several types of Java methods for each of the API's methods:
Taking ReadRows as an example for callable:
// These two invocation are equivalent
ServerStream<Row> stream1 = client.readRows(query);
ServerStream<Row> stream2 = client.readRowsCallable().call(query);
// These two invocation are also equivalent
client.readRowsAsync(query, observer);
client.readRowsCallable().call(query, observer);
All RPC related errors are represented as subclasses of ApiException. For example, a nonexistent table will trigger a NotFoundException. Async methods will wrap the error inside the future.
Synchronous methods will re-throw the async error but will try to preserve the caller's
stacktrace by attaching a suppressed exception at the callsite. This allows callers to use
typesafe exceptions, without losing their callsite. Streaming methods (ie. readRows) will
re-throw the async exception (like sync methods) when starting iteration.
See the individual methods for example code.
This class can be customized by passing in a custom instance of BigtableDataSettings to create(). For example:
To customize credentials:
BigtableDataSettings settings =
BigtableDataSettings.newBuilder()
.setProjectId("[PROJECT]")
.setInstanceId("[INSTANCE]")
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
BigtableDataClient client = BigtableDataClient.create(settings);
To customize the endpoint:
BigtableDataSettings.Builder settingsBuilder =
BigtableDataSettings.newBuilder()
.setProjectId("[PROJECT]")
.setInstanceId("[INSTANCE]");
settingsBuilder.stubSettings()
.setEndpoint(myEndpoint).build();
BigtableDataClient client = BigtableDataClient.create(settings.build());
| Modifier and Type | Method and Description |
|---|---|
void |
bulkMutateRows(BulkMutation mutation)
Convenience method to mutate multiple rows in a batch.
|
com.google.api.core.ApiFuture<Void> |
bulkMutateRowsAsync(BulkMutation mutation)
Convenience method to mutate multiple rows in a batch.
|
com.google.api.gax.rpc.UnaryCallable<BulkMutation,Void> |
bulkMutationCallable()
Mutates multiple rows in a batch.
|
Boolean |
checkAndMutateRow(ConditionalRowMutation mutation)
Convenience method to synchronously mutate a row atomically based on the output of a filter.
|
com.google.api.core.ApiFuture<Boolean> |
checkAndMutateRowAsync(ConditionalRowMutation mutation)
Convenience method to asynchronously mutate a row atomically based on the output of a filter.
|
com.google.api.gax.rpc.UnaryCallable<ConditionalRowMutation,Boolean> |
checkAndMutateRowCallable()
Mutates a row atomically based on the output of a filter.
|
void |
close()
Close the clients and releases all associated resources.
|
static BigtableDataClient |
create(BigtableDataSettings settings)
Constructs an instance of BigtableDataClient, using the given settings.
|
static BigtableDataClient |
create(String projectId,
String instanceId)
Constructs an instance of BigtableDataClient with default settings.
|
ResultSet |
executeQuery(BoundStatement boundStatement)
Executes a SQL Query and returns a ResultSet to iterate over the results.
|
boolean |
exists(String tableId,
com.google.protobuf.ByteString rowKey)
Deprecated.
Please use
exists(TargetId, ByteString) instead. |
boolean |
exists(String tableId,
String rowKey)
Deprecated.
Please use
exists(TargetId, String) instead. |
boolean |
exists(TargetId targetId,
com.google.protobuf.ByteString rowKey)
Confirms synchronously if given row key exists or not on the specified
TargetId. |
boolean |
exists(TargetId targetId,
String rowKey)
Confirms synchronously if given row key exists or not on the specified
TargetId. |
com.google.api.core.ApiFuture<Boolean> |
existsAsync(String tableId,
com.google.protobuf.ByteString rowKey)
Deprecated.
Please use
existsAsync(TargetId, ByteString) instead. |
com.google.api.core.ApiFuture<Boolean> |
existsAsync(String tableId,
String rowKey)
Deprecated.
Please use
existsAsync(TargetId, String) instead. |
com.google.api.core.ApiFuture<Boolean> |
existsAsync(TargetId targetId,
com.google.protobuf.ByteString rowKey)
Confirms asynchronously if given row key exists or not on the specified
TargetId. |
com.google.api.core.ApiFuture<Boolean> |
existsAsync(TargetId targetId,
String rowKey)
Confirms asynchronously if given row key exists or not on the specified
TargetId. |
com.google.api.gax.rpc.ServerStream<Range.ByteStringRange> |
generateInitialChangeStreamPartitions(String tableId)
Convenience method for synchronously streaming the partitions of a table.
|
void |
generateInitialChangeStreamPartitionsAsync(String tableId,
com.google.api.gax.rpc.ResponseObserver<Range.ByteStringRange> observer)
Convenience method for asynchronously streaming the partitions of a table.
|
com.google.api.gax.rpc.ServerStreamingCallable<String,Range.ByteStringRange> |
generateInitialChangeStreamPartitionsCallable()
Streams back the results of the query.
|
void |
mutateRow(RowMutation rowMutation)
Convenience method to synchronously mutate a single row atomically.
|
com.google.api.core.ApiFuture<Void> |
mutateRowAsync(RowMutation rowMutation)
Convenience method to asynchronously mutate a single row atomically.
|
com.google.api.gax.rpc.UnaryCallable<RowMutation,Void> |
mutateRowCallable()
Mutates a single row atomically.
|
com.google.api.gax.batching.Batcher<RowMutationEntry,Void> |
newBulkMutationBatcher(String tableId)
Deprecated.
Please use
newBulkMutationBatcher(TargetId) instead. |
com.google.api.gax.batching.Batcher<RowMutationEntry,Void> |
newBulkMutationBatcher(String tableId,
com.google.api.gax.grpc.GrpcCallContext ctx)
Deprecated.
Please use
newBulkMutationBatcher(TargetId,
GrpcCallContext) instead. |
com.google.api.gax.batching.Batcher<RowMutationEntry,Void> |
newBulkMutationBatcher(TargetId targetId)
Mutates multiple rows in a batch on the specified
TargetId. |
com.google.api.gax.batching.Batcher<RowMutationEntry,Void> |
newBulkMutationBatcher(TargetId targetId,
com.google.api.gax.grpc.GrpcCallContext ctx)
Mutates multiple rows in a batch on the specified
TargetId. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(String tableId)
Deprecated.
Please use
newBulkReadRowsBatcher(TargetId) instead. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(String tableId,
Filters.Filter filter)
Deprecated.
Please use
BigtableDataClient#newBulkReadRowsBatcher(TargetId, Filter)
instead. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(String tableId,
Filters.Filter filter,
com.google.api.gax.grpc.GrpcCallContext ctx)
Deprecated.
Please use
BigtableDataClient#newBulkReadRowsBatcher(TargetId, Filter,
GrpcCallContext) instead. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(TargetId targetId)
Reads rows for given tableId in a batch on the specified
TargetId. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(TargetId targetId,
Filters.Filter filter)
Reads rows for given tableId and filter criteria in a batch on the specified
TargetId. |
com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> |
newBulkReadRowsBatcher(TargetId targetId,
Filters.Filter filter,
com.google.api.gax.grpc.GrpcCallContext ctx)
Reads rows for given tableId and filter criteria in a batch on the specified
TargetId. |
PreparedStatement |
prepareStatement(String query,
Map<String,SqlType<?>> paramTypes)
Prepares a query for execution.
|
com.google.api.gax.rpc.ServerStream<ChangeStreamRecord> |
readChangeStream(ReadChangeStreamQuery query)
Convenience method for synchronously streaming the results of a
ReadChangeStreamQuery. |
void |
readChangeStreamAsync(ReadChangeStreamQuery query,
com.google.api.gax.rpc.ResponseObserver<ChangeStreamRecord> observer)
Convenience method for asynchronously streaming the results of a
ReadChangeStreamQuery. |
com.google.api.gax.rpc.ServerStreamingCallable<ReadChangeStreamQuery,ChangeStreamRecord> |
readChangeStreamCallable()
Streams back the results of the query.
|
Row |
readModifyWriteRow(ReadModifyWriteRow mutation)
Convenience method that synchronously modifies a row atomically on the server.
|
com.google.api.core.ApiFuture<Row> |
readModifyWriteRowAsync(ReadModifyWriteRow mutation)
Convenience method that asynchronously modifies a row atomically on the server.
|
com.google.api.gax.rpc.UnaryCallable<ReadModifyWriteRow,Row> |
readModifyWriteRowCallable()
Modifies a row atomically on the server.
|
Row |
readRow(String tableId,
com.google.protobuf.ByteString rowKey)
Deprecated.
Please use
readRow(TargetId, ByteString) instead. |
Row |
readRow(String tableId,
com.google.protobuf.ByteString rowKey,
Filters.Filter filter)
Deprecated.
Please use
BigtableDataClient#readRow(TargetId, ByteString, Filter)
instead. |
Row |
readRow(String tableId,
String rowKey)
Deprecated.
Please use
readRow(TargetId, String) instead. |
Row |
readRow(String tableId,
String rowKey,
Filters.Filter filter)
Deprecated.
Please use
BigtableDataClient#readRow(TargetId, String, Filter) instead. |
Row |
readRow(TargetId targetId,
com.google.protobuf.ByteString rowKey)
Convenience method for synchronously reading a single row on the specified
TargetId. |
Row |
readRow(TargetId targetId,
com.google.protobuf.ByteString rowKey,
Filters.Filter filter)
Convenience method for synchronously reading a single row on the specified
TargetId. |
Row |
readRow(TargetId targetId,
String rowKey)
Convenience method for synchronously reading a single row on the specified
TargetId. |
Row |
readRow(TargetId targetId,
String rowKey,
Filters.Filter filter)
Convenience method for synchronously reading a single row on the specified
TargetId. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(String tableId,
com.google.protobuf.ByteString rowKey)
Deprecated.
Please use
readRowAsync(TargetId, ByteString) instead. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(String tableId,
com.google.protobuf.ByteString rowKey,
Filters.Filter filter)
Deprecated.
Please use
BigtableDataClient#readRowAsync(TargetId, ByteString, Filter)
instead. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(String tableId,
String rowKey)
Deprecated.
Please use
readRowAsync(TargetId, String) instead. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(String tableId,
String rowKey,
Filters.Filter filter)
Deprecated.
Please use
BigtableDataClient#readRowAsync(TargetId, String, Filter)
instead. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(TargetId targetId,
com.google.protobuf.ByteString rowKey)
Convenience method for asynchronously reading a single row on the specified
TargetId. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(TargetId targetId,
com.google.protobuf.ByteString rowKey,
Filters.Filter filter)
Convenience method for asynchronously reading a single row on the specified
TargetId. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(TargetId targetId,
String rowKey)
Convenience method for asynchronously reading a single row on the specified
TargetId. |
com.google.api.core.ApiFuture<Row> |
readRowAsync(TargetId targetId,
String rowKey,
Filters.Filter filter)
Convenience method for asynchronously reading a single row on the specified
TargetId. |
com.google.api.gax.rpc.UnaryCallable<Query,Row> |
readRowCallable()
Reads a single row.
|
<RowT> com.google.api.gax.rpc.UnaryCallable<Query,RowT> |
readRowCallable(RowAdapter<RowT> rowAdapter)
Reads a single row.
|
com.google.api.gax.rpc.ServerStream<Row> |
readRows(Query query)
Convenience method for synchronously streaming the results of a
Query. |
void |
readRowsAsync(Query query,
com.google.api.gax.rpc.ResponseObserver<Row> observer)
Convenience method for asynchronously streaming the results of a
Query. |
com.google.api.gax.rpc.ServerStreamingCallable<Query,Row> |
readRowsCallable()
Streams back the results of the query.
|
<RowT> com.google.api.gax.rpc.ServerStreamingCallable<Query,RowT> |
readRowsCallable(RowAdapter<RowT> rowAdapter)
Streams back the results of the query.
|
List<KeyOffset> |
sampleRowKeys(String tableId)
Deprecated.
Please use
sampleRowKeys(TargetId) instead. |
List<KeyOffset> |
sampleRowKeys(TargetId targetId)
Convenience method to synchronously return a sample of row keys on the specified
TargetId. |
com.google.api.core.ApiFuture<List<KeyOffset>> |
sampleRowKeysAsync(String tableId)
Deprecated.
Please use
sampleRowKeysAsync(TargetId) instead. |
com.google.api.core.ApiFuture<List<KeyOffset>> |
sampleRowKeysAsync(TargetId targetId)
Convenience method to asynchronously return a sample of row keys on the specified
TargetId. |
com.google.api.gax.rpc.UnaryCallable<String,List<KeyOffset>> |
sampleRowKeysCallable()
Deprecated.
Please use
sampleRowKeysCallableWithRequest() instead. |
com.google.api.gax.rpc.UnaryCallable<SampleRowKeysRequest,List<KeyOffset>> |
sampleRowKeysCallableWithRequest()
Returns a sample of row keys in the table.
|
com.google.api.gax.rpc.ServerStreamingCallable<Query,Row> |
skipLargeRowsCallable()
Streams back the results of the read query & omits large rows.
|
<RowT> com.google.api.gax.rpc.ServerStreamingCallable<Query,RowT> |
skipLargeRowsCallable(RowAdapter<RowT> rowAdapter)
This is an internal API, it is subject to breaking changes and should not be relied on by user
code
Streams back the results of the query skipping the large-rows.
|
public static BigtableDataClient create(String projectId, String instanceId) throws IOException
projectId - The project id of the instance to connect to.instanceId - The id of the instance to connect to.IOException - If any.public static BigtableDataClient create(BigtableDataSettings settings) throws IOException
IOException@Deprecated public boolean exists(String tableId, String rowKey)
exists(TargetId, String) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
String key = "key";
boolean isRowPresent = bigtableDataClient.exists(tableId, key);
// Do something with result, for example, display a message
if(isRowPresent) {
System.out.println(key + " is present");
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurs@Deprecated public boolean exists(String tableId, com.google.protobuf.ByteString rowKey)
exists(TargetId, ByteString) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ByteString key = ByteString.copyFromUtf8("key");
boolean isRowPresent = bigtableDataClient.exists(tableId, key);
// Do something with result, for example, display a message
if(isRowPresent) {
System.out.println(key.toStringUtf8() + " is present");
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic boolean exists(TargetId targetId, String rowKey)
TargetId.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
String key = "key";
boolean isRowPresent = bigtableDataClient.exists(TableId.of(tableId), key);
// Do something with result, for example, display a message
if(isRowPresent) {
System.out.println(key + " is present");
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableIdpublic boolean exists(TargetId targetId, com.google.protobuf.ByteString rowKey)
TargetId.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ByteString key = ByteString.copyFromUtf8("key");
boolean isRowPresent = bigtableDataClient.exists(TableId.of(tableId), key);
// Do something with result, for example, display a message
if(isRowPresent) {
System.out.println(key.toStringUtf8() + " is present");
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableId@Deprecated public com.google.api.core.ApiFuture<Boolean> existsAsync(String tableId, String rowKey)
existsAsync(TargetId, String) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
final String key = "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 + " is present");
}
}
}, MoreExecutors.directExecutor());
}
@Deprecated public com.google.api.core.ApiFuture<Boolean> existsAsync(String tableId, com.google.protobuf.ByteString rowKey)
existsAsync(TargetId, ByteString) instead.Sample 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());
}
public com.google.api.core.ApiFuture<Boolean> existsAsync(TargetId targetId, String rowKey)
TargetId.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
final String key = "key";
ApiFuture<Boolean> futureResult = bigtableDataClient.existsAsync(TableId.of(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 + " is present");
}
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic com.google.api.core.ApiFuture<Boolean> existsAsync(TargetId targetId, com.google.protobuf.ByteString rowKey)
TargetId.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
final ByteString key = ByteString.copyFromUtf8("key");
ApiFuture<Boolean> futureResult = bigtableDataClient.existsAsync(TableId.of(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());
}
AuthorizedViewId,
TableId@Deprecated public Row readRow(String tableId, com.google.protobuf.ByteString rowKey)
readRow(TargetId, ByteString) instead.Sample code:
{code
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Row row = bigtableDataClient.readRow(tableId, ByteString.copyFromUtf8("key"));
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
}com.google.api.gax.rpc.ApiException - when a serverside error occurs@Deprecated public Row readRow(String tableId, String rowKey)
readRow(TargetId, String) instead.Sample code:
{code
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Row row = bigtableDataClient.readRow(tableId, "key");
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
}com.google.api.gax.rpc.ApiException - when a serverside error occurs@Deprecated public Row readRow(String tableId, String rowKey, @Nullable Filters.Filter filter)
BigtableDataClient#readRow(TargetId, String, Filter) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
Row row = bigtableDataClient.readRow(tableId, "key", filter);
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurs@Deprecated public Row readRow(String tableId, com.google.protobuf.ByteString rowKey, @Nullable Filters.Filter filter)
BigtableDataClient#readRow(TargetId, ByteString, Filter)
instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
Row row = bigtableDataClient.readRow(tableId, ByteString.copyFromUtf8("key"), filter);
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic Row readRow(TargetId targetId, com.google.protobuf.ByteString rowKey)
TargetId. If
the row does not exist, the value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Row row = bigtableDataClient.readRow(TableId.of(tableId), ByteString.copyFromUtf8("key"));
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableIdpublic Row readRow(TargetId targetId, String rowKey)
TargetId. If
the row does not exist, the value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Row row = bigtableDataClient.readRow(TableId.of(tableId), "key");
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableIdpublic Row readRow(TargetId targetId, String rowKey, @Nullable Filters.Filter filter)
TargetId. If
the row does not exist, the value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
Row row = bigtableDataClient.readRow(TableId.of(tableId), "key", filter);
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableIdpublic Row readRow(TargetId targetId, com.google.protobuf.ByteString rowKey, @Nullable Filters.Filter filter)
TargetId. If
the row does not exist, the value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
Row row = bigtableDataClient.readRow(TableId.of(tableId), ByteString.copyFromUtf8("key"), filter);
// Do something with row, for example, display all cells
if(row != null) {
System.out.println(row.getKey().toStringUtf8());
for(RowCell cell : row.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s", cell.getFamily(),
cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursAuthorizedViewId,
TableId@Deprecated public com.google.api.core.ApiFuture<Row> readRowAsync(String tableId, String rowKey)
readRowAsync(TargetId, String) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(tableId, "key");
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
@Deprecated public com.google.api.core.ApiFuture<Row> readRowAsync(String tableId, com.google.protobuf.ByteString rowKey)
readRowAsync(TargetId, ByteString) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(tableId, ByteString.copyFromUtf8("key"));
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row row) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
@Deprecated public com.google.api.core.ApiFuture<Row> readRowAsync(String tableId, String rowKey, @Nullable Filters.Filter filter)
BigtableDataClient#readRowAsync(TargetId, String, Filter)
instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filters.Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(tableId, "key", filter);
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row row) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
@Deprecated public com.google.api.core.ApiFuture<Row> readRowAsync(String tableId, com.google.protobuf.ByteString rowKey, @Nullable Filters.Filter filter)
BigtableDataClient#readRowAsync(TargetId, ByteString, Filter)
instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filters.Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(tableId, ByteString.copyFromUtf8("key"), filter);
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row row) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
public com.google.api.core.ApiFuture<Row> readRowAsync(TargetId targetId, String rowKey)
TargetId.
If the row does not exist, the future's value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(TableId.of(tableId), "key");
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic com.google.api.core.ApiFuture<Row> readRowAsync(TargetId targetId, com.google.protobuf.ByteString rowKey)
TargetId.
If the row does not exist, the future's value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(TableId.of(tableId), ByteString.copyFromUtf8("key"));
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic com.google.api.core.ApiFuture<Row> readRowAsync(TargetId targetId, String rowKey, @Nullable Filters.Filter filter)
TargetId.
If the row does not exist, the future's value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filters.Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(TableId.of(tableId), "key", filter);
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic com.google.api.core.ApiFuture<Row> readRowAsync(TargetId targetId, com.google.protobuf.ByteString rowKey, @Nullable Filters.Filter filter)
TargetId.
If the row does not exist, the value will be null.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Build the filter expression
Filters.Filter filter = FILTERS.chain()
.filter(FILTERS.qualifier().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
ApiFuture<Row> futureResult = bigtableDataClient.readRowAsync(TableId.of(tableId), ByteString.copyFromUtf8("key"), filter);
ApiFutures.addCallback(futureResult, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
if (result != null) {
System.out.println("Got row: " + result);
}
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic com.google.api.gax.rpc.UnaryCallable<Query,Row> readRowCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.rowKey("[KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Synchronous invocation
try {
Row row = bigtableDataClient.readRowCallable().call(query);
if (row == null) {
System.out.println("Row not found");
}
} catch (RuntimeException e) {
e.printStackTrace();
}
// Asynchronous invocation
ApiFuture<Row> rowFuture = bigtableDataClient.readRowCallable().futureCall(query);
ApiFutures.addCallback(rowFuture, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row row) {
if (row == null) {
System.out.println("Row not found");
}
}
}, MoreExecutors.directExecutor());
}
For call styles.,
For query options.,
For the filter building DSL.public <RowT> com.google.api.gax.rpc.UnaryCallable<Query,RowT> readRowCallable(RowAdapter<RowT> rowAdapter)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.rowKey("[KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Synchronous invocation
CustomRow row = bigtableDataClient.readRowCallable(new CustomRowAdapter()).call(query));
// Do something with row
}
For call styles.,
For query options.,
For the filter building DSL.public com.google.api.gax.rpc.ServerStream<Row> readRows(Query query)
Query. The returned
ServerStream instance is not threadsafe, it can only be used from single thread.
Sample code:
// Import the filter DSL
import static com.google.cloud.bigtable.data.v2.models.Filters.FILTERS;
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
try {
ServerStream<Row> stream = bigtableDataClient.readRows(query);
int count = 0;
// Iterator style
for (Row row : stream) {
if (++count > 10) {
stream.cancel();
break;
}
// Do something with row
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For call styles.,
For query options.,
For the filter building DSL.public void readRowsAsync(Query query, com.google.api.gax.rpc.ResponseObserver<Row> observer)
Query.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
bigtableDataClient.readRowsAsync(query, new ResponseObserver<Row>() {
StreamController controller;
int count = 0;
public void onStart(StreamController controller) {
this.controller = controller;
}
public void onResponse(Row row) {
if (++count > 10) {
controller.cancel();
return;
}
// Do something with Row
}
public void onError(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onComplete() {
// Handle stream completion
}
});
}
public com.google.api.gax.rpc.ServerStreamingCallable<Query,Row> readRowsCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Iterator style
try {
for(Row row : bigtableDataClient.readRowsCallable().call(query)) {
// Do something with row
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Sync style
try {
List<Row> rows = bigtableDataClient.readRowsCallable().all().call(query);
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Point look up
ApiFuture<Row> rowFuture = bigtableDataClient.readRowsCallable().first().futureCall(query);
ApiFutures.addCallback(rowFuture, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row result) {
System.out.println("Got row: " + result);
}
}, MoreExecutors.directExecutor());
// etc
}
For call styles.,
For query options.,
For the filter building DSL.@InternalApi(value="only to be used by Bigtable beam connector") public com.google.api.gax.rpc.ServerStreamingCallable<Query,Row> skipLargeRowsCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Iterator style
try {
for(Row row : bigtableDataClient.skipLargeRowsCallable().call(query)) {
// Do something with row
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Sync style
try {
List<Row> rows = bigtableDataClient.skipLargeRowsCallable().all().call(query);
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// etc
}
For call styles.,
For query options.,
For the filter building DSL.public <RowT> com.google.api.gax.rpc.ServerStreamingCallable<Query,RowT> readRowsCallable(RowAdapter<RowT> rowAdapter)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Iterator style
try {
for(CustomRow row : bigtableDataClient.readRowsCallable(new CustomRowAdapter()).call(query)) {
// Do something with row
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For call styles.,
For query options.,
For the filter building DSL.@InternalApi(value="only to be used by Bigtable beam connector") public <RowT> com.google.api.gax.rpc.ServerStreamingCallable<Query,RowT> skipLargeRowsCallable(RowAdapter<RowT> rowAdapter)
Streams back the results of the query skipping the large-rows. This callable allows for customization of the logical representation of a row. It's meant for advanced use cases.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
Query query = Query.create(tableId)
.range("[START KEY]", "[END KEY]")
.filter(FILTERS.qualifier().regex("[COLUMN PREFIX].*"));
// Iterator style
try {
for(CustomRow row : bigtableDataClient.skipLargeRowsCallable(new CustomRowAdapter()).call(query)) {
// Do something with row
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For call styles.,
For query options.,
For the filter building DSL.@Deprecated public List<KeyOffset> sampleRowKeys(String tableId)
sampleRowKeys(TargetId) instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE_ID]";
List<KeyOffset> keyOffsets = bigtableDataClient.sampleRowKeys(tableId);
for(KeyOffset keyOffset : keyOffsets) {
// Do something with keyOffset
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic List<KeyOffset> sampleRowKeys(TargetId targetId)
TargetId.
The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE_ID]";
List<KeyOffset> keyOffsets = bigtableDataClient.sampleRowKeys(TableId.of(tableId));
for(KeyOffset keyOffset : keyOffsets) {
// Do something with keyOffset
}
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurs@Deprecated public com.google.api.core.ApiFuture<List<KeyOffset>> sampleRowKeysAsync(String tableId)
sampleRowKeysAsync(TargetId) instead.Sample code:
try (BigtableClient bigtableDataClient = BigtableClient.create("[PROJECT]", "[INSTANCE]")) {
ApiFuture<List<KeyOffset>> keyOffsetsFuture = bigtableClient.sampleRowKeysAsync("[TABLE]");
ApiFutures.addCallback(keyOffsetsFuture, new ApiFutureCallback<List<KeyOffset>>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to sample keys of a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(List<KeyOffset> keyOffsets) {
System.out.println("Got key offsets: " + keyOffsets);
}
}, MoreExecutors.directExecutor());
}
public com.google.api.core.ApiFuture<List<KeyOffset>> sampleRowKeysAsync(TargetId targetId)
TargetId.
The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.
Sample code:
try (BigtableClient bigtableDataClient = BigtableClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE_ID]";
ApiFuture<List<KeyOffset>> keyOffsetsFuture = bigtableClient.sampleRowKeysAsync(TableId.of(tableId));
ApiFutures.addCallback(keyOffsetsFuture, new ApiFutureCallback<List<KeyOffset>>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to sample keys of a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(List<KeyOffset> keyOffsets) {
System.out.println("Got key offsets: " + keyOffsets);
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableId@Deprecated public com.google.api.gax.rpc.UnaryCallable<String,List<KeyOffset>> sampleRowKeysCallable()
sampleRowKeysCallableWithRequest() instead.Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
// Synchronous invocation
try {
List<KeyOffset> keyOffsets = bigtableDataClient.sampleRowKeysCallable().call("[TABLE]");
} catch (NotFoundException e) {
System.out.println("Tried to sample keys of a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Asynchronous invocation
ApiFuture<List<KeyOffset>> keyOffsetsFuture = bigtableDataClient.sampleRowKeysCallable().futureCall("[TABLE]");
ApiFutures.addCallback(keyOffsetsFuture, new ApiFutureCallback<List<KeyOffset>>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to sample keys of a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(List<KeyOffset> keyOffsets) {
System.out.println("Got key offsets: " + keyOffsets);
}
}, MoreExecutors.directExecutor());
}
public com.google.api.gax.rpc.UnaryCallable<SampleRowKeysRequest,List<KeyOffset>> sampleRowKeysCallableWithRequest()
SampleRowKeysRequest object rather than a String input, and thus can be used to sample against
a specified TargetId.
The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces. The returned callable object allows for customization of api invocation.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
SampleRowKeysRequest sampleRowKeys = SampleRowKeysRequest.create(TableId.of("[TABLE]"));
// Synchronous invocation
try {
List<KeyOffset> keyOffsets = bigtableDataClient.sampleRowKeysCallableWithRequest().call(sampleRowKeys);
} catch (NotFoundException e) {
System.out.println("Tried to sample keys of a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Asynchronous invocation
ApiFuture<List<KeyOffset>> keyOffsetsFuture = bigtableDataClient.sampleRowKeysCallableWithRequest().futureCall(sampleRowKeys);
ApiFutures.addCallback(keyOffsetsFuture, new ApiFutureCallback<List<KeyOffset>>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to sample keys of a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(List<KeyOffset> keyOffsets) {
System.out.println("Got key offsets: " + keyOffsets);
}
}, MoreExecutors.directExecutor());
}
AuthorizedViewId,
TableIdpublic void mutateRow(RowMutation rowMutation)
RowMutation.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
RowMutation mutation = RowMutation.create("[TABLE]", "[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]");
bigtableDataClient.mutateRow(mutation);
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic com.google.api.core.ApiFuture<Void> mutateRowAsync(RowMutation rowMutation)
RowMutation.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
RowMutation mutation = RowMutation.create("[TABLE]", "[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]");
ApiFuture<Void> future = bigtableDataClient.mutateRowAsync(mutation);
ApiFutures.addCallback(future, new ApiFutureCallback<Void>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to mutate a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Void ignored) {
System.out.println("Successfully applied mutation");
}
}, MoreExecutors.directExecutor());
}
public com.google.api.gax.rpc.UnaryCallable<RowMutation,Void> mutateRowCallable()
RowMutation.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
RowMutation mutation = RowMutation.create("[TABLE]", "[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]");
// Sync style
try {
bigtableDataClient.mutateRowCallable().call(mutation);
} catch (NotFoundException e) {
System.out.println("Tried to mutate a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
public void bulkMutateRows(BulkMutation mutation)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
BulkMutation batch = BulkMutation.create("[TABLE]");
for (String someValue : someCollection) {
batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
bigtableDataClient.bulkMutateRows(batch);
} catch(ApiException e) {
e.printStackTrace();
} catch(MutateRowsException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occursMutateRowsException - if any of the entries
failed to be applied@Deprecated public com.google.api.gax.batching.Batcher<RowMutationEntry,Void> newBulkMutationBatcher(@Nonnull String tableId)
newBulkMutationBatcher(TargetId) instead.Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
try (Batcher<RowMutationEntry, Void> batcher = bigtableDataClient.newBulkMutationBatcher("[TABLE]")) {
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture =
batcher.add(
RowMutationEntry.create("[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
// Blocks until mutations are applied on all submitted row entries.
batcher.flush();
}
// Before `batcher` is closed, all remaining(If any) mutations are applied.
}
@Deprecated public com.google.api.gax.batching.Batcher<RowMutationEntry,Void> newBulkMutationBatcher(@Nonnull String tableId, @Nullable com.google.api.gax.grpc.GrpcCallContext ctx)
newBulkMutationBatcher(TargetId,
GrpcCallContext) instead.GrpcCallContext. The same
context will be reused for all batches. This can be used to customize things like per attempt
timeouts.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
try (Batcher<RowMutationEntry, Void> batcher = bigtableDataClient.newBulkMutationBatcher("[TABLE]", GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(10)))) {
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture =
batcher.add(
RowMutationEntry.create("[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
// Blocks until mutations are applied on all submitted row entries.
batcher.flush();
}
// Before `batcher` is closed, all remaining(If any) mutations are applied.
}
@BetaApi(value="This surface is likely to change as the batching surface evolves.") public com.google.api.gax.batching.Batcher<RowMutationEntry,Void> newBulkMutationBatcher(TargetId targetId)
TargetId.
Each individual row is mutated atomically as in MutateRow, but the entire batch is not executed atomically. The returned Batcher instance is not threadsafe, it can only be used from single thread.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
try (Batcher<RowMutationEntry, Void> batcher = bigtableDataClient.newBulkMutationBatcher(TableId.of("[TABLE]"))) {
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture =
batcher.add(
RowMutationEntry.create("[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
// Blocks until mutations are applied on all submitted row entries.
batcher.flush();
}
// Before `batcher` is closed, all remaining(If any) mutations are applied.
}
AuthorizedViewId,
TableId@BetaApi(value="This surface is likely to change as the batching surface evolves.") public com.google.api.gax.batching.Batcher<RowMutationEntry,Void> newBulkMutationBatcher(TargetId targetId, @Nullable com.google.api.gax.grpc.GrpcCallContext ctx)
TargetId.
Each individual row is mutated atomically as in MutateRow, but the entire batch is not
executed atomically. The returned Batcher instance is not threadsafe, it can only be used from
single thread. This method allows customization of the underlying RPCs by passing in a GrpcCallContext. The same context will be reused for all batches. This
can be used to customize things like per attempt timeouts.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
GrpcCallContext ctx = GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(10));
try (Batcher<RowMutationEntry, Void> batcher = bigtableDataClient.newBulkMutationBatcher(TableId.of("[TABLE]"), ctx)) {
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture =
batcher.add(
RowMutationEntry.create("[ROW KEY]")
.setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
// Blocks until mutations are applied on all submitted row entries.
batcher.flush();
}
// Before `batcher` is closed, all remaining(If any) mutations are applied.
}
AuthorizedViewId,
TableId@Deprecated public com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(String tableId)
newBulkReadRowsBatcher(TargetId) instead.Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher("[TABLE]")) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
@Deprecated public com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(String tableId, @Nullable Filters.Filter filter)
BigtableDataClient#newBulkReadRowsBatcher(TargetId, Filter)
instead.Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.key().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher("[TABLE]", filter)) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
@Deprecated public com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(String tableId, @Nullable Filters.Filter filter, @Nullable com.google.api.gax.grpc.GrpcCallContext ctx)
BigtableDataClient#newBulkReadRowsBatcher(TargetId, Filter,
GrpcCallContext) instead.GrpcCallContext. The same context will be reused for all batches. This
can be used to customize things like per attempt timeouts.
Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.key().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher(
"[TABLE]", filter, GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(10)))) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
public com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(TargetId targetId)
TargetId.
If the row does not exist, the value will be null. The returned Batcher instance is not threadsafe, it can only be used from a single thread.
Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher(TableId.of("[TABLE]"))) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
AuthorizedViewId,
TableIdpublic com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(TargetId targetId, @Nullable Filters.Filter filter)
TargetId.
If the row does not exist, the value will be null. The returned Batcher instance is not threadsafe, it can only be used from a single thread.
Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.key().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher(TableId.of("[TABLE]"), filter)) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
AuthorizedViewId,
TableIdpublic com.google.api.gax.batching.Batcher<com.google.protobuf.ByteString,Row> newBulkReadRowsBatcher(TargetId targetId, @Nullable Filters.Filter filter, @Nullable com.google.api.gax.grpc.GrpcCallContext ctx)
TargetId.
If the row does not exist, the value will be null. The returned Batcher instance is not
threadsafe, it can only be used from a single thread. This method allows customization of the
underlying RPCs by passing in a GrpcCallContext. The same
context will be reused for all batches. This can be used to customize things like per attempt
timeouts.
Performance notice: The ReadRows protocol requires that rows are sent in ascending key order, which means that the keys are processed sequentially on the server-side, so batching allows improving throughput but not latency. Lower latencies can be achieved by sending smaller requests concurrently.
Sample Code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
// Build the filter expression
Filter filter = FILTERS.chain()
.filter(FILTERS.key().regex("prefix.*"))
.filter(FILTERS.limit().cellsPerRow(10));
List<ApiFuture<Row>> rows = new ArrayList<>();
try (Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher(
TableId.of("[TABLE]"), filter, GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(10)))) {
for (String someValue : someCollection) {
ApiFuture<Row> rowFuture =
batcher.add(ByteString.copyFromUtf8("[ROW KEY]"));
rows.add(rowFuture);
}
// [Optional] Sends collected elements for batching asynchronously.
batcher.sendOutstanding();
// [Optional] Invokes sendOutstanding() and awaits until all pending entries are resolved.
batcher.flush();
}
// batcher.close() invokes `flush()` which will in turn invoke `sendOutstanding()` with await for
pending batches until its resolved.
List<Row> actualRows = ApiFutures.allAsList(rows).get();
}
AuthorizedViewId,
TableIdpublic com.google.api.core.ApiFuture<Void> bulkMutateRowsAsync(BulkMutation mutation)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create("[PROJECT]", "[INSTANCE]")) {
BulkMutation batch = BulkMutation.create("[TABLE]");
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture = batch.add("[ROW KEY]",
Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
}
ApiFuture<Void> resultFuture = bigtableDataClient.bulkMutateRowsAsync(batch);
ApiFutures.addCallback(resultFuture, new ApiFutureCallback<Void>() {
public void onFailure(Throwable t) {
if (t instanceof BulkMutationFailure) {
System.out.println("Some entries failed to apply");
} else {
t.printStackTrace();
}
}
public void onSuccess(Void ignored) {
System.out.println("Successfully applied all mutation");
}
}, MoreExecutors.directExecutor());
}
public com.google.api.gax.rpc.UnaryCallable<BulkMutation,Void> bulkMutationCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
BulkMutation batch = BulkMutation.create("[TABLE]");
for (String someValue : someCollection) {
ApiFuture<Void> entryFuture = batch.add("[ROW KEY]",
Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]");
}
bigtableDataClient.bulkMutationCallable().call(batch);
}
public Boolean checkAndMutateRow(ConditionalRowMutation mutation)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ConditionalRowMutation mutation = ConditionalRowMutation.create("[TABLE]", "[KEY]")
.condition(FILTERS.value().regex("old-value"))
.then(
Mutation.create()
.setCell("[FAMILY]", "[QUALIFIER]", "[VALUE]")
);
Boolean result = bigtableDataClient.checkAndMutateRow(mutation);
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic com.google.api.core.ApiFuture<Boolean> checkAndMutateRowAsync(ConditionalRowMutation mutation)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ConditionalRowMutation mutation = ConditionalRowMutation.create("[TABLE]", "[KEY]")
.condition(FILTERS.value().regex("old-value"))
.then(
Mutation.create()
.setCell("[FAMILY]", "[QUALIFIER]", "[VALUE]")
);
ApiFuture<Boolean> future = bigtableDataClient.checkAndMutateRowAsync(mutation);
ApiFutures.addCallback(future, new ApiFutureCallback<Boolean>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to mutate a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Boolean wasApplied) {
System.out.println("Row was modified: " + wasApplied);
}
}, MoreExecutors.directExecutor());
}
public com.google.api.gax.rpc.UnaryCallable<ConditionalRowMutation,Boolean> checkAndMutateRowCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ConditionalRowMutation mutation = ConditionalRowMutation.create("[TABLE]", "[KEY]")
.condition(FILTERS.value().regex("old-value"))
.then(
Mutation.create()
.setCell("[FAMILY]", "[QUALIFIER]", "[VALUE]")
);
// Sync style
try {
boolean success = bigtableDataClient.checkAndMutateRowCallable().call(mutation);
if (!success) {
System.out.println("Row did not match conditions");
}
} catch (NotFoundException e) {
System.out.println("Tried to mutate a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
public Row readModifyWriteRow(ReadModifyWriteRow mutation)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
.increment("[FAMILY]", "[QUALIFIER]", 1)
.append("[FAMILY2]", "[QUALIFIER2]", "suffix");
Row success = bigtableDataClient.readModifyWriteRow(mutation);
} catch(ApiException e) {
e.printStackTrace();
}
com.google.api.gax.rpc.ApiException - when a serverside error occurspublic com.google.api.core.ApiFuture<Row> readModifyWriteRowAsync(ReadModifyWriteRow mutation)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
.increment("[FAMILY]", "[QUALIFIER]", 1)
.append("[FAMILY2]", "[QUALIFIER2]", "suffix");
ApiFuture<Row> rowFuture = bigtableDataClient.readModifyWriteRowAsync(mutation);
ApiFutures.addCallback(rowFuture, new ApiFutureCallback<Row>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to mutate a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(Row resultingRow) {
System.out.println("Resulting row: " + resultingRow);
}
}, MoreExecutors.directExecutor());
}
public com.google.api.gax.rpc.UnaryCallable<ReadModifyWriteRow,Row> readModifyWriteRowCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
.increment("[FAMILY]", "[QUALIFIER]", 1)
.append("[FAMILY2]", "[QUALIFIER2]", "suffix");
try {
Row row = bigtableDataClient.readModifyWriteRowCallable().call(mutation);
} catch (NotFoundException e) {
System.out.println("Tried to mutate a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public com.google.api.gax.rpc.ServerStream<Range.ByteStringRange> generateInitialChangeStreamPartitions(String tableId)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
try {
ServerStream<ByteStringRange> stream = bigtableDataClient.generateInitialChangeStreamPartitions(tableId);
int count = 0;
// Iterator style
for (ByteStringRange partition : stream) {
if (++count > 10) {
stream.cancel();
break;
}
// Do something with partition
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For call styles.@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public void generateInitialChangeStreamPartitionsAsync(String tableId, com.google.api.gax.rpc.ResponseObserver<Range.ByteStringRange> observer)
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
bigtableDataClient.generateInitialChangeStreamPartitionsAsync(tableId, new ResponseObserver<RowRange>() {
StreamController controller;
int count = 0;
public void onStart(StreamController controller) {
this.controller = controller;
}
public void onResponse(ByteStringRange partition) {
if (++count > 10) {
controller.cancel();
return;
}
// Do something with partition
}
public void onError(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onComplete() {
// Handle stream completion
}
});
}
@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public com.google.api.gax.rpc.ServerStreamingCallable<String,Range.ByteStringRange> generateInitialChangeStreamPartitionsCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
// Iterator style
try {
for(ByteStringRange partition : bigtableDataClient.generateInitialChangeStreamPartitionsCallable().call(tableId)) {
// Do something with partition
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Sync style
try {
List<ByteStringRange> partitions = bigtableDataClient.generateInitialChangeStreamPartitionsCallable().all().call(tableId);
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Point look up
ApiFuture<ByteStringRange> partitionFuture =
bigtableDataClient.generateInitialChangeStreamPartitionsCallable().first().futureCall(tableId);
ApiFutures.addCallback(partitionFuture, new ApiFutureCallback<ByteStringRange>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(RowRange result) {
System.out.println("Got partition: " + result);
}
}, MoreExecutors.directExecutor());
// etc
}
For call styles.@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public com.google.api.gax.rpc.ServerStream<ChangeStreamRecord> readChangeStream(ReadChangeStreamQuery query)
ReadChangeStreamQuery.
The returned ServerStream instance is not threadsafe, it can only be used from single thread.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ReadChangeStreamQuery query = ReadChangeStreamQuery.create(tableId)
.streamPartition("START_KEY", "END_KEY")
.startTime(Timestamp.newBuilder().setSeconds(100).build());
try {
ServerStream<ChangeStreamRecord> stream = bigtableDataClient.readChangeStream(query);
int count = 0;
// Iterator style
for (ChangeStreamRecord record : stream) {
if (++count > 10) {
stream.cancel();
break;
}
// Do something with the change stream record.
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For call styles.,
For query options.@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public void readChangeStreamAsync(ReadChangeStreamQuery query, com.google.api.gax.rpc.ResponseObserver<ChangeStreamRecord> observer)
ReadChangeStreamQuery.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ReadChangeStreamQuery query = ReadChangeStreamQuery.create(tableId)
.streamPartition("START_KEY", "END_KEY")
.startTime(Timestamp.newBuilder().setSeconds(100).build());
bigtableDataClient.readChangeStreamAsync(query, new ResponseObserver<ChangeStreamRecord>() {
StreamController controller;
int count = 0;
public void onStart(StreamController controller) {
this.controller = controller;
}
public void onResponse(ChangeStreamRecord record) {
if (++count > 10) {
controller.cancel();
return;
}
// Do something with the change stream record.
}
public void onError(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onComplete() {
// Handle stream completion
}
});
}
@InternalApi(value="Intended for use by the BigtableIO in apache/beam only.") public com.google.api.gax.rpc.ServerStreamingCallable<ReadChangeStreamQuery,ChangeStreamRecord> readChangeStreamCallable()
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String tableId = "[TABLE]";
ReadChangeStreamQuery query = ReadChangeStreamQuery.create(tableId)
.streamPartition("START_KEY", "END_KEY")
.startTime(Timestamp.newBuilder().setSeconds(100).build());
// Iterator style
try {
for(ChangeStreamRecord record : bigtableDataClient.readChangeStreamCallable().call(query)) {
// Do something with record
}
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Sync style
try {
List<ChangeStreamRecord> records = bigtableDataClient.readChangeStreamCallable().all().call(query);
} catch (NotFoundException e) {
System.out.println("Tried to read a non-existent table");
} catch (RuntimeException e) {
e.printStackTrace();
}
// Point look up
ApiFuture<ChangeStreamRecord> recordFuture =
bigtableDataClient.readChangeStreamCallable().first().futureCall(query);
ApiFutures.addCallback(recordFuture, new ApiFutureCallback<ChangeStreamRecord>() {
public void onFailure(Throwable t) {
if (t instanceof NotFoundException) {
System.out.println("Tried to read a non-existent table");
} else {
t.printStackTrace();
}
}
public void onSuccess(ChangeStreamRecord result) {
System.out.println("Got record: " + result);
}
}, MoreExecutors.directExecutor());
// etc
}
For call styles.,
For query options.public ResultSet executeQuery(BoundStatement boundStatement)
The BoundStatement must be built from a PreparedStatement created using the
same instance and app profile.
Sample code:
try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
String query = "SELECT CAST(cf['stringCol'] AS STRING) FROM [TABLE]";
Map<String, SqlType<?>> paramTypes = new HashMap<>();
PreparedStatement preparedStatement = bigtableDataClient.prepareStatement(query, paramTypes));
// Ideally one PreparedStatement should be reused across requests
BoundStatement boundStatement = preparedStatement.bind()
// set any query params before calling build
.build();
try (ResultSet resultSet = bigtableDataClient.executeQuery(boundStatement)) {
while (resultSet.next()) {
String s = resultSet.getString("stringCol");
// do something with data
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
for query options.,
for query options.public PreparedStatement prepareStatement(String query, Map<String,SqlType<?>> paramTypes)
A parameterized query should contain placeholders in the form of @ followed by the parameter name. Parameter names may consist of any combination of letters, numbers, and underscores.
Parameters can appear anywhere that a literal value is expected. The same parameter name can
be used more than once, for example: WHERE cf["qualifier1"] = @value OR cf["qualifier2"]
= @value
query - sql query string to prepareparamTypes - a Map of the parameter names and the corresponding SqlType for all
query parameters in 'query'PreparedStatement which is used to create BoundStatements to executepublic void close()
close in interface AutoCloseableCopyright © 2026 Google LLC. All rights reserved.