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

Add Bookmark support for mango json queries #740

Merged
merged 3 commits into from
Aug 16, 2017
Merged

Add Bookmark support for mango json queries #740

merged 3 commits into from
Aug 16, 2017

Conversation

garrensmith
Copy link
Member

This adds a bookmark that is sent with each query and can be used to
continue a query from a specific key. This will allow users to paginate
mango queries.

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

This adds a bookmark that is sent with each query and can be used to
continue a query from a specific key. This will allow users to paginate
mango queries.
@willholley
Copy link
Member

testing a basic case where no results are returned, I get a response:

{"warning":"no matching index found, create an index to optimize query time",
"docs":[
],
"bookmark": "nil"}

However, passing "nil" back as a bookmark returns an error:

$ curl 'http://127.0.0.1:15984/test/_find' -H 'Content-Type:application/json' -d '{"selector":{"id":"willnotmatch"},"bookmark":"nil"}'
{"error":"invalid_bookmark","reason":"Invalid bookmark value: \"nil\""}

@willholley
Copy link
Member

suggest adding a pagination test where each document emits the same value into the index to ensure progress is made using startkey_docid.

@garrensmith
Copy link
Member Author

Thanks @willholley I've fixed the issue and added another test.

nil;
unpack(Packed) ->
try
binary_to_term(couch_util:decodeBase64Url(Packed))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part got me thinking a bit. What is a valid vs invalid bookmark? So when unpacked, a json bookmark is a start_key and end_key range, and a text bookmark is a node+shard range. So the composition is slightly different. So a text index bookmark should be considered invalid for a json index bookmark right? When I tried that particular scenario, the bookmark passed correctly Here's a sample text bookmark: "g2wAAAACaAJkAA5zdGFydGtleV9kb2NpZG0AAAAkZTkwMDAwMWQtYmM0OC00OGE2LTliMWEtYWM5YTFmNWQxYTAzaAJkAAhzdGFydGtleWsAAStq" .

If you did it the other way around...substitute a json index bookmark into a text index bookmark, it fails with invalid_bookmark.

Wondering if we should be more consistent/strict and and verify both types of bookmarks?

catch _:_ ->
?MANGO_ERROR({invalid_bookmark, Packed})
end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow? Do you want me to remove that new line or add another?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, it showed no new end of line. just normal end of file new line is fine

@@ -305,8 +315,20 @@ doc_member(Db, RowProps, Opts) ->
end
end.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace change

@garrensmith
Copy link
Member Author

@tonysun83 thanks for the review. I've make some fixes based on your feedback

@tonysun83
Copy link
Contributor

+1 after that fixing that weird end of line issue

@garrensmith garrensmith merged commit 89e99e5 into apache:master Aug 16, 2017
wohali pushed a commit that referenced this pull request Oct 19, 2017
This adds a bookmark that is sent with each query and can be used to
continue a query from a specific key. This will allow users to paginate
mango queries.
willholley pushed a commit to willholley/couchdb that referenced this pull request May 22, 2018
This adds a bookmark that is sent with each query and can be used to
continue a query from a specific key. This will allow users to paginate
mango queries.
@garrensmith garrensmith deleted the bookmarks-mango branch December 12, 2019 17:20
@anuragvohraec
Copy link

This adds a bookmark that is sent with each query and can be used to
continue a query from a specific key. This will allow users to paginate
mango queries.

How exactly is bookmark implmented? [I have no knowledge of Erlang, but have written a couchdb client in dart]. Is it base64 enocded of json of last index[or doc] sent to user ?

@garrensmith
Copy link
Member Author

@anuragvohraec the code is here https://github.com/apache/couchdb/blob/master/src/mango/src/mango_json_bookmark.erl
We basically take the startkey and startkey_docid and convert to erlang binary and then to base64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants