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:
  • Method Details

    • 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 the BigtableDataSettings.
    • rowKey

      public Query rowKey(String key)
      Adds a key to looked up
    • rowKey

      public Query rowKey(com.google.protobuf.ByteString key)
      Adds a key to looked up
    • prefix

      public Query prefix(com.google.protobuf.ByteString prefix)
    • prefix

      public Query prefix(String 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 use Filters.interleave() or Filters.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 from 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();
       
    • 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 com.google.bigtable.v2.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 com.google.bigtable.v2.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.

    • clone

      public Query clone()
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object