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.
This would definitely be very helpful in building rich applications with Riak without having to resort to some middle ware to apply sorting across an intermediate result set.
Regarding ordering - being able to specify sort order would be a huge boon, although I can only begin to imagine how difficult this would be in a distributed system and the latency that might introduce into a system.
Otherwise, ignoring the implementation details, I'd love to see ordering on either the index, the query, or both.
Are strings sorted ASCII-betically? I ask because ASCIIbetical sorting would make it easy to do "begins with" type queries, which is often a common case for querying - e.g. with an index on a properly ISO formatted timestamp, I can easily find and aggregate at various levels.