Database Reference
In-Depth Information
Exclusive start key
A query request always returns only 1 MB of data at a time. To fetch more data, there is a
strategy available using the exclusive start key.
One of the most important concepts for the ScanRequest operation is the usage of the
exclusive start key. But the same could be used in QueryRequest too. Usually, whenev-
er we use the exclusive start key, it is mandatory to use the limit parameter. Only two new
parameters (the other three parameters are already discussed) are configured to
QueryRequest .
• The withQueryFilter() method is used to set the query filter map to the
query request
• The last method, withExclusiveStartKey() , is used to notify the
QueryRequest instance about the key of the item evaluated at present
If we observe the do... while loop closely, we see that we submit the
QueryRequest instance for every ten items retrieved. For example, if 95 items satisfy
both the key and query filter conditions, then this loop will be executed 10 times. During
the first execution, lastEvaluatedKey will be null. During the second iteration
lastEvaluatedKey will be the tenth item. During the tenth iteration, it will again be-
come null. Have a look at the following code:
Map<String, AttributeValue> lastEvaluatedKey = null ;
do {
QueryRequest queryRequest = new QueryRequest()
.withTableName( "Tbl_Book" )
.withKeyConditions(keyCndtns)
.withQueryFilter(queryFilter)
.withLimit(10)
.withExclusiveStartKey(lastEvaluatedKey);
QueryResult result = client .query(queryRequest);
lastEvaluatedKey = result.getLastEvaluatedKey();
}
while (lastEvaluatedKey != null );
As soon as the query request is submitted, it will return only (a maximum of) ten items at a
time. While executing the loop for the second time, the last evaluated item's (tenth item's)
key will decide the entry point for this query request. So the second QueryRequest will
Search WWH ::




Custom Search