{"action":"created","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-java/issues/339","labels_url":"https://api.github.com/repos/aws/aws-sdk-java/issues/339/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-java/issues/339/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-java/issues/339/events","html_url":"https://github.com/aws/aws-sdk-java/issues/339","id":53756975,"number":339,"title":"Doubts on DynamoDB queryPage combined with Limit and a queryFilter or a FilterExpression","user":{"login":"ricardclau","id":613725,"avatar_url":"https://avatars.githubusercontent.com/u/613725?v=3","gravatar_id":"","url":"https://api.github.com/users/ricardclau","html_url":"https://github.com/ricardclau","followers_url":"https://api.github.com/users/ricardclau/followers","following_url":"https://api.github.com/users/ricardclau/following{/other_user}","gists_url":"https://api.github.com/users/ricardclau/gists{/gist_id}","starred_url":"https://api.github.com/users/ricardclau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricardclau/subscriptions","organizations_url":"https://api.github.com/users/ricardclau/orgs","repos_url":"https://api.github.com/users/ricardclau/repos","events_url":"https://api.github.com/users/ricardclau/events{/privacy}","received_events_url":"https://api.github.com/users/ricardclau/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-08T14:38:58Z","updated_at":"2015-01-08T18:08:28Z","closed_at":null,"body":"Hi\r\n\r\nI am querying a GSI index in Dynamo where I have a HashKey and RangeKey defined, I would like to limit the results to a small number (let's say 5) and I need to add a FilterExpression so that when the user queries this index he does not get his own records.\r\n\r\nThe problem I am facing is that it looks like the limit gets executed before either the queryFilter or the filterExpression. So, basically if one out of the 5 records happens to be affected by the queryFilter or the filterExpression it gets discarded and I end up getting less than 5 elements when looking at the getResults method.\r\n\r\nIs this the expected behaviour from the library? A DynamoDB restriction? Is there any way to have the filter executed after the limit (apart from obviously checking the size and querying again or add a higher limit)?\r\n\r\nAny help would be much appreciated"},"comment":{"url":"https://api.github.com/repos/aws/aws-sdk-java/issues/comments/69221743","html_url":"https://github.com/aws/aws-sdk-java/issues/339#issuecomment-69221743","issue_url":"https://api.github.com/repos/aws/aws-sdk-java/issues/339","id":69221743,"user":{"login":"david-at-aws","id":5216241,"avatar_url":"https://avatars.githubusercontent.com/u/5216241?v=3","gravatar_id":"","url":"https://api.github.com/users/david-at-aws","html_url":"https://github.com/david-at-aws","followers_url":"https://api.github.com/users/david-at-aws/followers","following_url":"https://api.github.com/users/david-at-aws/following{/other_user}","gists_url":"https://api.github.com/users/david-at-aws/gists{/gist_id}","starred_url":"https://api.github.com/users/david-at-aws/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/david-at-aws/subscriptions","organizations_url":"https://api.github.com/users/david-at-aws/orgs","repos_url":"https://api.github.com/users/david-at-aws/repos","events_url":"https://api.github.com/users/david-at-aws/events{/privacy}","received_events_url":"https://api.github.com/users/david-at-aws/received_events","type":"User","site_admin":false},"created_at":"2015-01-08T18:08:28Z","updated_at":"2015-01-08T18:08:28Z","body":"One quick way to handle this is to use ```query()``` instead of ```queryPage()``` and only read the first 5 items from the returned list. ```query()``` handles pagination for you, so it'll automatically make another call to DynamoDB if needed to fetch the additional records.\r\n\r\n```java\r\n// Limit of 5 is passed through to the service on each query; we might get fewer than 5 results though.\r\nList<MyObject> objects = mapper.query(query.withLimit(5));\r\n\r\nfor (int i = 0; i < 5; ++i) {\r\n    // get() will make another call to DynamoDB if the first page of results didn't include enough\r\n    // results.\r\n    MyObject obj = objects.get(i);\r\n    ...\r\n}\r\n```"}}