Class Query (2.39.4)

public final class Query implements Serializable

A simple wrapper to construct a query for the ReadRows RPC.

Inheritance

Object > Query

Implements

Serializable

Static Methods

create(TargetId targetId)

public static Query create(TargetId targetId)

Constructs a new Query object for the given target with targetId. The target id will be combined with the instance name specified in the com.google.cloud.bigtable.data.v2.BigtableDataSettings. See Also: TableId, AuthorizedViewId

Parameter
Name Description
targetId TargetId
Returns
Type Description
Query

create(String tableId) (deprecated)

public static Query create(String tableId)

Deprecated. Please use Query#create(TargetId) instead.

Parameter
Name Description
tableId String
Returns
Type Description
Query

fromProto(ReadRowsRequest request)

public static Query fromProto(ReadRowsRequest request)

Wraps the protobuf ReadRowsRequest.

WARNING: Please note that the project id & instance id in the table name will be overwritten by the configuration in the BigtableDataClient.

Parameter
Name Description
request com.google.bigtable.v2.ReadRowsRequest
Returns
Type Description
Query

Methods

clone()

public Query clone()
Returns
Type Description
Query
Overrides

createPaginator(int pageSize)

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));
 
Parameter
Name Description
pageSize int
Returns
Type Description
Query.QueryPaginator

equals(Object o)

public boolean equals(Object o)
Parameter
Name Description
o Object
Returns
Type Description
boolean
Overrides

filter(Filters.Filter 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 use Filters#interleave() or Filters#chain().

Parameter
Name Description
filter Filters.Filter
Returns
Type Description
Query

getBound()

public Range.ByteStringRange getBound()

Get the minimal range that encloses all of the row keys and ranges in this Query.

Returns
Type Description
Range.ByteStringRange

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

limit(long limit)

public Query limit(long limit)

Limits the number of rows that can be returned

Parameter
Name Description
limit long
Returns
Type Description
Query

prefix(ByteString prefix)

public Query prefix(ByteString prefix)
Parameter
Name Description
prefix ByteString
Returns
Type Description
Query

prefix(String prefix)

public Query prefix(String prefix)
Parameter
Name Description
prefix String
Returns
Type Description
Query

range(Range.ByteStringRange range)

public Query range(Range.ByteStringRange range)

Adds a range to be looked up.

Parameter
Name Description
range Range.ByteStringRange
Returns
Type Description
Query

range(ByteString start, ByteString end)

public Query range(ByteString start, ByteString end)

Adds a range to be looked up.

Parameters
Name Description
start ByteString

The beginning of the range (inclusive). Can be null to represent negative infinity.

end ByteString

The end of the range (exclusive). Can be null to represent positive infinity.

Returns
Type Description
Query

range(String start, String end)

public Query range(String start, String end)

Adds a range to be looked up.

Parameters
Name Description
start String

The beginning of the range (inclusive). Can be null to represent negative infinity.

end String

The end of the range (exclusive). Can be null to represent positive infinity.

Returns
Type Description
Query

reversed(boolean enable)

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)
 
Parameter
Name Description
enable boolean
Returns
Type Description
Query

rowKey(ByteString key)

public Query rowKey(ByteString key)

Adds a key to looked up

Parameter
Name Description
key ByteString
Returns
Type Description
Query

rowKey(String key)

public Query rowKey(String key)

Adds a key to looked up

Parameter
Name Description
key String
Returns
Type Description
Query

shard(List<KeyOffset> sampledRowKeys)

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 from com.google.cloud.bigtable.data.v2.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
Parameter
Name Description
sampledRowKeys List<KeyOffset>
Returns
Type Description
List<Query>

shard(SortedSet<ByteString> splitPoints)

public List<Query> shard(SortedSet<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
Parameter
Name Description
splitPoints SortedSet<ByteString>
Returns
Type Description
List<Query>

toProto(RequestContext requestContext)

public ReadRowsRequest toProto(RequestContext requestContext)

Creates the request protobuf. This method is considered an internal implementation detail and not meant to be used by applications.

Parameter
Name Description
requestContext com.google.cloud.bigtable.data.v2.internal.RequestContext
Returns
Type Description
com.google.bigtable.v2.ReadRowsRequest

toString()

public String toString()
Returns
Type Description
String
Overrides