public final class Query extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
Query.QueryPaginator
A Query Paginator that will split a query into small chunks.
|
| Modifier and Type | Method and Description |
|---|---|
Query |
clone() |
static Query |
create(String tableId)
Deprecated.
Please use
create(TargetId) instead. |
static Query |
create(TargetId targetId)
Constructs a new Query object for the given target with targetId.
|
Query.QueryPaginator |
createPaginator(int pageSize)
Create a query paginator that'll split the query into smaller chunks.
|
boolean |
equals(Object o) |
Query |
filter(Filters.Filter filter)
Sets the filter to apply to each row.
|
static Query |
fromProto(ReadRowsRequest request)
Wraps the protobuf
ReadRowsRequest. |
Range.ByteStringRange |
getBound()
Get the minimal range that encloses all of the row keys and ranges in this Query.
|
TargetId |
getTargetId() |
int |
hashCode() |
Query |
limit(long limit)
Limits the number of rows that can be returned
|
Query |
prefix(com.google.protobuf.ByteString prefix) |
Query |
prefix(String prefix) |
Query |
range(com.google.protobuf.ByteString start,
com.google.protobuf.ByteString end)
Adds a range to be looked up.
|
Query |
range(Range.ByteStringRange range)
Adds a range to be looked up.
|
Query |
range(String start,
String end)
Adds a range to be looked up.
|
Query |
reversed(boolean enable)
Return rows in reverse order.
|
Query |
rowKey(com.google.protobuf.ByteString key)
Adds a key to looked up
|
Query |
rowKey(String key)
Adds a key to looked up
|
List<Query> |
shard(List<KeyOffset> sampledRowKeys)
Split this query into multiple queries that can be evenly distributed across Bigtable nodes and
be run in parallel.
|
List<Query> |
shard(SortedSet<com.google.protobuf.ByteString> splitPoints)
Split this query into multiple queries that logically combine into this query.
|
ReadRowsRequest |
toProto(com.google.cloud.bigtable.data.v2.internal.RequestContext requestContext)
Creates the request protobuf.
|
SessionReadRowRequest |
toSessionPointProto() |
String |
toString() |
@Deprecated public static Query create(String tableId)
create(TargetId) instead.public static Query create(TargetId targetId)
BigtableDataSettings.AuthorizedViewId,
MaterializedViewId,
TableIdpublic Query rowKey(com.google.protobuf.ByteString key)
public Query prefix(com.google.protobuf.ByteString prefix)
public Query range(String start, String end)
start - The beginning of the range (inclusive). Can be null to represent negative
infinity.end - The end of the range (exclusive). Can be null to represent positive infinity.public Query range(com.google.protobuf.ByteString start, com.google.protobuf.ByteString end)
start - The beginning of the range (inclusive). Can be null to represent negative
infinity.end - The end of the range (exclusive). Can be null to represent positive infinity.public Query range(Range.ByteStringRange range)
public Query filter(Filters.Filter filter)
Filters.interleave() or Filters.chain().public Query limit(long limit)
public Query reversed(boolean enable)
The row will be streamed in reverse lexiographic order of the keys. The row key ranges are still expected to be oriented the same way as forwards. ie [a,c] where a <= c. The row content will remain unchanged from the ordering forward scans. This is particularly useful to get the last N records before a key:
query
.range(ByteStringRange.unbounded().endOpen("key"))
.limit(10)
.reversed(true)
public List<Query> shard(List<KeyOffset> sampledRowKeys)
BigtableDataClient.sampleRowKeysAsync(String) to divide this
query into a set of disjoint queries that logically combine into form this query.
Expected Usage:
List<KeyOffset> keyOffsets = dataClient.sampleRowKeysAsync("my-table").get();
List<Query> queryShards = myQuery.shard(keyOffsets);
List<ApiFuture<List<Row>>> futures = new ArrayList();
for (Query subQuery : queryShards) {
futures.add(dataClient.readRowsCallable().all().futureCall(subQuery));
}
List<List<Row>> results = ApiFutures.allAsList(futures).get();
public List<Query> shard(SortedSet<com.google.protobuf.ByteString> splitPoints)
Expected Usage:
List<ByteString> splitPoints = ...;
List<Query> queryShards = myQuery.shard(splitPoints);
List<ApiFuture<List<Row>>> futures = new ArrayList();
for (Query subQuery : queryShards) {
futures.add(dataClient.readRowsCallable().all().futureCall(subQuery));
}
List<List<Row>> results = ApiFutures.allAsList(futures).get();
@BetaApi(value="This surface is stable yet it might be removed in the future.") public Query.QueryPaginator createPaginator(int pageSize)
Example usage:
Query query = Query.create(...).range("a", "z");
Query.QueryPaginator paginator = query.createQueryPaginator(100);
ByteString lastSeenRowKey = ByteString.EMPTY;
do {
List<Row> rows = client.readRowsCallable().all().call(paginator.getNextQuery());
for (Row row : rows) {
// do some processing
lastSeenRow = row;
}
} while (paginator.advance(lastSeenRowKey));
public Range.ByteStringRange getBound()
@InternalApi public TargetId getTargetId()
@InternalApi public SessionReadRowRequest toSessionPointProto()
@InternalApi public ReadRowsRequest toProto(com.google.cloud.bigtable.data.v2.internal.RequestContext requestContext)
public static Query fromProto(@Nonnull ReadRowsRequest request)
ReadRowsRequest.
WARNING: Please note that the project id & instance id in the table name will be overwritten by the configuration in the BigtableDataClient.
Copyright © 2026 Google LLC. All rights reserved.