public class DatastoreShardStrategy extends Object
DatastoreInput
to shard queries.
This is done in one of two ways:
1. If the query contains an inequality filter, the lower and upper bounds are determined (this
may involve querying the datastore) then the range is split naively. This works well when the
property that is being queried on is uniformly distributed.
2. If the query does not contain an inequality filter. The query will be partitioned by the
entity key. This is done by using the "__scatter__" property to get a random sample of the
keyspace and partitioning based on that. This can result in a poor distribution if there are
equality filters on the query that bias the selection with respect to certain regions of
keyspace.
The following clauses are not supported by this class: An inequality filter of unsupported type.
(Only numeric and date types are currently supported:
"https://developers.google.com/appengine/docs/java/datastore/entities#Java_Properties_and_value_types"
)
Filters that are incompatible with datastore cursors such as: Combining multiple clauses with an
OR. A filter on a value being NOT_EQUAL. A filter on a value being IN a set.
"https://developers.google.com/appengine/docs/java/datastore/queries#Java_Limitations_of_cursors"Modifier and Type | Method and Description |
---|---|
List<com.google.appengine.api.datastore.Query> |
splitQuery(com.google.appengine.api.datastore.Query query,
int numSegments) |
public List<com.google.appengine.api.datastore.Query> splitQuery(com.google.appengine.api.datastore.Query query, int numSegments)
query
- the query to divide into multiple queriesnumSegments
- the number of queries to divide the inputQuery into. The actual result may
contain fewer if it cannot be divided that finely.Copyright © 2015 Google. All rights reserved.