Riak Users,
I've been working on some new features for Riak's secondary indexes (2i), and I wanted to get some feedback from the community before proceeding much further.
2i lets you query index values with an equality query, or with an inclusive range query. The results are not sorted in any way.
-
Results will now be sorted by [IndexValue, PrimaryKey] in ascending-order. I'm unsure if supporting descending-order queries is important-enough to do now, or add in later.
-
Queries can specify a limit for the number of results to return. As expected, the limit is applied after sorting
-
Queries can constrain the results returned based on the index-value being
eq
(equal),lt
(less than),lte
(less-than-or-equal),gt
orgte
. Queries can also provide no constraints, which will return the whole index (before limiting that is). -
Queries can "continue" where a previous query left-off. This provides a limited form of pagination. Note, there is no snapshotting or isolation between queries using a continuation. The continuations have no server-side state, and last forever.
Queries are described as JSON data-structures. The query is for a specific Bucket/Index, which is specified either in the path (for HTTP) or in the PB message.
// return the first 100 keys
// whose index value is
// greater-than-or-equal to "bar" and
// less-than "foo"
{
"limit": 100,
"query": {
"gte": "bar",
"lt": "foo"
}
}
// this query will return a continuation that will
// let you ask for more results, starting at
// the 101st value
// return all the keys whose index
// value is greater-than 50
{
"query": {
"gt": 50,
}
}
// return all of the keys whose
// index value is equal to 33
{
"query": {
"eq": 33
}
}
// ask for 100 more results using a continuation
// from a previous query. Note, requests with
// continuations should _not_ include a query
// section, as that is wrapped up in the continuation
// already
{
"continuation": "a85hYGBgymBKYWBKLcwFshklQRyWnMTiErAUR",
"limit": 100
}
-
Will it help you do things with 2i that you wanted to do but previously weren't able?
-
How important is it to be able to specify the sort oder (ASC vs. DESC)?
-
Any other thoughts are appreciated as well.
Ordering of any kind will help greatly, in my experience. It'd be nice to have the descending ordering, as well as ascending, but if the latter is easier, I'm OK with punting on the former right now.
Is there any reason why the 2i stuff is represented as a JSON? I guess, coming from Ruby, I can pass in a Hash that'll get serialized into JSON, but is this an efficient method for other languages, especially ones with more ceremony like Java?
Other than that, it looks great. I very much like the continuation option. I need to experiment with the current 2i implementation to see how it behaves with dates before making a comment on that.