the first example given in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryingJavaDocumentAPI.html which returns a ItemCollection
According to http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination we need to get the lastevaluatedkey and perform the query again but there isn't any getlastevaluatedkey for a ItemCollection that is returned from dynamoDb.getTable("tableName").query(keyattribute)
Also ItemCollection documentation states that n/w calls would be made if iterated across page boundary so do we have to make calls till again as given in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination or not
Asked
Active
Viewed 6,362 times
4

smac2020
- 9,637
- 4
- 24
- 38

shrewquest
- 541
- 1
- 7
- 22
2 Answers
3
getLastEvaluatedKey is a method of QueryResult (or ScanResult).
In the example you refer to, a collection of QueryOutcome is used, bypassing the QueryResult. To get the last evaluated key, you could try doing this
QueryRequest request = new QueryRequest();
request.setTableName(tablename);
QueryResult result = dynamoDB.query(request);
ItemCollection<QueryOutcome> items = result.getItems();
Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
I hope this helps.

quodlibet
- 452
- 3
- 8
0
Once you have the Map - you can further process the returned data. For example, in this example, the key name and data are pushed into two ArrayList objects:
ArrayList<String> keys = new ArrayList<String>();
ArrayList<String> keyVals = new ArrayList<String>();
for (Map<String, AttributeValue> item : result.getItems()) {
Set<String> key = item.keySet();
Collection<AttributeValue> values = item.values();
for (Iterator<String> it = key.iterator(); it.hasNext(); ) {
String f = it.next();
System.out.println(f);
keys.add(f);
}
for (Iterator<AttributeValue> it2 = values.iterator(); it2.hasNext(); ) {
AttributeValue v1 = it2.next();
String yy= v1.getS();
keyVals.add(yy);
}
}
Then you can do what you need to do with the returned data

smac2020
- 9,637
- 4
- 24
- 38