My team at Moz is planning on using sortdb to hold data indexed by timestamps. We'd like to create an API endpoint to allow range matching between one key and another, based on the existing sorting of the keys:
/range?start=key1&end=key2...
Some examples:
For the DB with these keys:
| Input |
Expected records |
Comments |
/range?start=bb&end=d |
bb, c, cc |
Standard use case. |
/range?start=a&end=cc |
b, bb, c, cc |
If the start key precedes the first key in the db, gets all records until the end key. |
/range?start=a&end=c |
b, bb, c |
Note the expectation here compared to the last call: this will not use prefix match as fwmatch does, in order to avoid confusion about which keys are retrieved. |
/range?start=c&end=z |
c, cc, f |
If the end key is out of range, gets all records from the first match to the start key onward. |
/range?start=g&end=z |
404 Error: NOT_FOUND |
As expected, nothing is returned if there is no key found in that range. |
/range?start=z&end=a |
400 Error: MALFORMED_RANGE |
Error is returned if end comes before start in sort order. |
Note that for ease of reading, I didn't include records or delimit the keys with newlines. In reality, the expected output format would be the same as expected for fwmatch.
We'd particularly find this handy for our use case (since we could then pick out data corresponding to a range of dates), but we also believe it'll be a useful endpoint to add in general since clients of sortdb will naturally take advantage of the sorted nature of the DB when choosing their keys. Since the data is retrieved sequentially, range match can (and should) be a fast operation.
I plan to implement this in the Go version of sortdb, but I'd also like to add it to the C version if that's still in active use and development. In either case, I wanted to open up this issue first so that any questions or concerns about the endpoint can be ironed out first. Please let me know if you have any feedback on this before I proceed. Thank you!
My team at Moz is planning on using sortdb to hold data indexed by timestamps. We'd like to create an API endpoint to allow range matching between one key and another, based on the existing sorting of the keys:
Some examples:
For the DB with these keys:
/range?start=bb&end=d/range?start=a&end=cc/range?start=a&end=cfwmatchdoes, in order to avoid confusion about which keys are retrieved./range?start=c&end=z/range?start=g&end=z/range?start=z&end=aendcomes beforestartin sort order.Note that for ease of reading, I didn't include records or delimit the keys with newlines. In reality, the expected output format would be the same as expected for
fwmatch.We'd particularly find this handy for our use case (since we could then pick out data corresponding to a range of dates), but we also believe it'll be a useful endpoint to add in general since clients of sortdb will naturally take advantage of the sorted nature of the DB when choosing their keys. Since the data is retrieved sequentially, range match can (and should) be a fast operation.
I plan to implement this in the Go version of sortdb, but I'd also like to add it to the C version if that's still in active use and development. In either case, I wanted to open up this issue first so that any questions or concerns about the endpoint can be ironed out first. Please let me know if you have any feedback on this before I proceed. Thank you!