I am trying to query DynamoDB with help of DynamoDBMapper in Java with both hashKey and rangeKey. But I am not getting all results, it returns only some part of it. My code looks like:
queryDynamoDb() {
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.GT.toString())
.withAttributeValueList(new AttributeValue().withS("0"));
DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression(
new AttributeValue().withS(prefKey));
queryExpression.setRangeKeyCondition(rangeKeyCondition);
List<MyObj> myobjs = mapper.query(MyObj.class, queryExpression);
return myobjs;
}
MyObj is properly annotated with DynamoDB annotations. So I am able to save the objects, but retrieval returns a partial result only.
The documentation of query within DynamoDBMapper says:
The query method returns the “lazy-loaded” collection. That is, initially it returns only one page of results. It makes a service call for the next page when needed.
Now the question is, how to tell the mapper to make a service call or that a page is needed, so it loads all pages (effectively all entries)?
The Java code snippet within the Amazon DynamoDB documentation for the DynamoDBMapper Class is a bit unfortunate here (though technologically correct), the AWS SDK for Java API documentation for Class DynamoDBMapper is (naturally) more precise in this regard, see method query():
So the returned type is actually a Class PaginatedQueryList:
That is, you really do not need to explicitly load anything during normal usage, insofar it is implicitly taken care of by the lazy-loading implementation of
PaginatedQueryList<T>; however, if so desired for whatever reason, you can trigger it by operations requiring access to the entire collection, with the explicitly mentioned size() method being one of them apparently.