throws DatastoreException {
Query.Builder scatterPointQuery = createScatterQuery(query, numSplits);
List<Key> keySplits = new ArrayList<Key>();
QueryResultBatch batch;
do {
RunQueryRequest scatterRequest = RunQueryRequest.newBuilder()
.setQuery(scatterPointQuery).build();
batch = datastore.runQuery(scatterRequest).getBatch();
for (EntityResult result : batch.getEntityResultList()) {
keySplits.add(result.getEntity().getKey());
}
scatterPointQuery.setStartCursor(batch.getEndCursor());
scatterPointQuery.setLimit(scatterPointQuery.getLimit() - batch.getEntityResultCount());
} while (batch.getMoreResults() == MoreResultsType.NOT_FINISHED);
Collections.sort(keySplits, DatastoreHelper.getKeyComparator());
return keySplits;
}