Question

I am using DynamoDBMapper for a class, let's say "User" (username being the primary key) which has a field on it which says "Status". It is a Hash+Range key table, and everytime a user's status changes (changes are extremely infrequent), we add a new entry to the table alongwith the timestamp (which is the range key). To fetch the current status, this is what I am doing:

    DynamoDBQueryExpression expr =
        new DynamoDBQueryExpression(new AttributeValue().withS(userName))
               .withScanIndexForward(false).withLimit(1);

    PaginatedQueryList<User> result = 
                this.getMapper().query(User.class, expr);

    if(result == null || result.size() == 0) {
        return null;
    }

    for(final User user : result) {
        System.out.println(user.getStatus());
    }

This for some reason, is printing all the statuses a user has had till now. I have set scanIndexForward to false so that it is in descending order and I put limit of 1. I am expecting this to return the latest single entry in the table for that username.

However, when I even look into the wire logs of the same, I see a huge amount of entries being returned, much more than 1. For now, I am using:

final String currentStatus = result.get(0).getStatus();

What I am trying to understand here is, what is whole point of the withLimit clause in this case, or am I doing something wrong?

Was it helpful?

Solution

In March 2013 on the AWS forums a user complained about the same problem.

A representative from Amazon sent him to use the queryPage function.

It seems as if the limit is not preserved for elements but rather a limit on chunk of elements retrieved in a single API call, and the queryPage might help.

You could also look into the pagination loading strategy configuration

Also, you can always open a Github issue for the team.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top