Paging through unordered partitioner results

Using CQL to page through rows.

When using the RandomPartitioner or Murmur3Partitioner, Cassandra rows are ordered by the hash of their value and hence the order of rows is not meaningful. Despite that fact, given the following definition:

CREATE TABLE test (
  k int PRIMARY KEY,
  v1 int,
  v2 int
);

and assuming RandomPartitioner or Murmur3Partitioner, CQL 2 allows queries like:

SELECT * FROM test WHERE k > 42;

The semantics of such a query is to query all rows for which the hash of the key was bigger than the hash of 42. The query would return results where k ≤ 42, which is unintuitive.

CQL 3 forbids such a query unless the partitioner in use is ordered. Even when using the random partitioner or the murmur3 partitioner, it can sometimes be useful to page through all rows. For this purpose, CQL 3 includes the token function:

SELECT * FROM test WHERE token(k) > token(42);

The ByteOrdered partitioner arranges tokens the same way as key values, but the RandomPartitioner and Murmur3Partitioner distribute tokens in a completely unordered manner. The token function makes it possible to page through unordered partitioner results. Using the token function actually queries results directly using tokens. Underneath, the token function makes token-based comparisons and does not convert keys to tokens (not k > 42).