Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:limit not working with query function #74

Closed
johnboy14 opened this issue Dec 1, 2015 · 5 comments · Fixed by #143
Closed

:limit not working with query function #74

johnboy14 opened this issue Dec 1, 2015 · 5 comments · Fixed by #143

Comments

@johnboy14
Copy link

I'm trying to paginate results but my query doesn't seem to limit the result set as expected. Just to be clear I'm querying a table with a composite key of :id and :timestamp. The table has 25 items with the same :id.

(far/query client-opts table {:id [:eq id]} {:limit 10})                                            

Another thing. How do I retrieve the LastEvaluatedKey in my results.

@wit-0-bit
Copy link

Hello @johnboy14,

I know its been a while, but I ran into this today and I might have found the cause so I figured I would share in case someone else runs into this.

You might want to check out the span-reqs option. By default, it is set {:max 5} and splits the query amongst a maximum of 5 requests. When max is set to values other than 1, it seems to be a little fuzzy about how many actual results to return. For example, setting it to {:max 2} and setting :limit 2 I received 4 results back. The result count was consistent with :limit when I tried something like:

(far/query client-opts table {:id [:eq id]} {:limit 10 :span-reqs {:max 1}})  

I am not 100% sure that is what you are experiencing, but it might be worth checking out.

About your other question, you can get the LastEvaluatedKey out of the result's meta, where it is stored as last-prim-kvs. For example:

(let [query-results (far/query client-opts table {:id [:eq id]}  {:limit 10 :span-reqs {:max 1}})]
  (:last-prim-kvs (meta query-results)))

I hope this helps

@johnboy14
Copy link
Author

I eventually worked out I needed to use the :span-reqs option with a limit value but I wasn't aware that I could pull the :last-prim-kvs using the meta function, so thanks for that.

@belucid
Copy link
Collaborator

belucid commented Dec 4, 2018

This one OK to close @johnboy14 ? Or do you have any suggestions for the docs?

@belucid belucid added can close? and removed bug? labels Dec 4, 2018
@smoes
Copy link

smoes commented Dec 10, 2018

I ran into the very same problem and I'd still consider this a bug.

Expanding docs would be a patch and fine as a first step, but not the correct solution in my opinion.
DynamoDB's query/scan behaves differently concerning the limit param, doesn't it? I would definitely expect the number I pass to limit to be the maximal number of returned items.

@belucid belucid self-assigned this Dec 26, 2018
@belucid belucid added this to To do in 1.10 Release Dec 26, 2018
@kipz
Copy link
Collaborator

kipz commented Nov 3, 2019

Would a :span-reqs/max default of 0 (i.e. do nothing) be what people would expect there? We could also have an option to make that infinite. In either case, it might make sense to return a lazy-sequence (if we're not already).

I'd be quite happy for the :limit to simply be the value that is sent to dynamodb, and not necessarily be the limit on number of results returned by faraday, but the current default of span-reqs/max of 5 is probably never what I want (either 0 or infinite are more common for me).

joelittlejohn added a commit that referenced this issue Nov 25, 2019
Until now, the default 'span-reqs' configuration stitched up to 5
requests together if last-prim-kvs implied it was necessary. This caused
confusion because it's not getting all results but it's also not
limited to just one page. The limit parameter also then became
confusing, because the number of items returned by a request would be
somewhere between '5' and '5 x limit'.

After this commit the various 'get items' functions will return only one
page by default and if subsequent pages are needed then span-reqs must
be used.

Closes #74
@kipz kipz closed this as completed in #143 Nov 26, 2019
joelittlejohn added a commit that referenced this issue Jul 19, 2020
Looks like I missed this one. See #74, #143 and commit 9b4cb80.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
1.10 Release
  
To do
Development

Successfully merging a pull request may close this issue.

6 participants