Class Query
- java.lang.Object
-
- com.google.cloud.bigtable.data.v2.models.Query
-
- All Implemented Interfaces:
Serializable
public final class Query extends Object implements Serializable
A simple wrapper to construct a query for the ReadRows RPC.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Query.QueryPaginator
A Query Paginator that will split a query into small chunks.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Query
clone()
static Query
create(String tableId)
Constructs a new Query object for the specified table id.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 protobufReadRowsRequest
.Range.ByteStringRange
getBound()
Get the minimal range that encloses all of the row keys and ranges in this Query.int
hashCode()
Query
limit(long limit)
Limits the number of rows that can be returnedQuery
prefix(com.google.protobuf.ByteString prefix)
Query
prefix(String prefix)
Query
range(Range.ByteStringRange range)
Adds a range to be looked up.Query
range(com.google.protobuf.ByteString start, com.google.protobuf.ByteString end)
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 upQuery
rowKey(String key)
Adds a key to looked upList<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.String
toString()
-
-
-
Method Detail
-
create
public static Query create(String tableId)
Constructs a new Query object for the specified table id. The table id will be combined with the instance name specified in theBigtableDataSettings
.
-
rowKey
public Query rowKey(com.google.protobuf.ByteString key)
Adds a key to looked up
-
prefix
public Query prefix(com.google.protobuf.ByteString prefix)
-
range
public Query range(String start, String end)
Adds a range to be looked up.- Parameters:
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.
-
range
public Query range(com.google.protobuf.ByteString start, com.google.protobuf.ByteString end)
Adds a range to be looked up.- Parameters:
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.
-
range
public Query range(Range.ByteStringRange range)
Adds a range to be looked up.
-
filter
public Query filter(Filters.Filter filter)
Sets the filter to apply to each row. Only one filter can be set at a time. To use multiple filters, please useFilters.interleave()
orFilters.chain()
.
-
limit
public Query limit(long limit)
Limits the number of rows that can be returned
-
reversed
public Query reversed(boolean enable)
Return rows in reverse order.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)
-
shard
public 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. This method takes the results fromBigtableDataClient.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();
-
shard
public List<Query> shard(SortedSet<com.google.protobuf.ByteString> splitPoints)
Split this query into multiple queries that logically combine into this query. This is intended to be used by map reduce style frameworks like Beam to split a query across multiple workers.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();
-
createPaginator
@BetaApi("This surface is stable yet it might be removed in the future.") public Query.QueryPaginator createPaginator(int pageSize)
Create a query paginator that'll split the query into smaller chunks.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));
-
getBound
public Range.ByteStringRange getBound()
Get the minimal range that encloses all of the row keys and ranges in this Query.
-
toProto
@InternalApi public ReadRowsRequest toProto(com.google.cloud.bigtable.data.v2.internal.RequestContext requestContext)
Creates the request protobuf. This method is considered an internal implementation detail and not meant to be used by applications.
-
fromProto
public static Query fromProto(@Nonnull ReadRowsRequest request)
Wraps the protobufReadRowsRequest
.WARNING: Please note that the project id & instance id in the table name will be overwritten by the configuration in the BigtableDataClient.
-
-