Displaying rows from an unordered partitioner with the TOKEN function
How to use CQL to display rows from an unordered partitioner.
The ByteOrdered partitioner arranges tokens the same way as key values, but the RandomPartitioner and Murmur3Partitioner distribute tokens in a completely unordered manner. When using the RandomPartitioner or Murmur3Partitioner, Cassandra rows are ordered by the hash of their partition key, or for one partition queries, rows are ordered by their clustering key. Hence, the order of rows is not meaningful, because of the hashes generated.
To order the rows for display when using RandomPartitioner or Murmur3Partitioner, the
token function may be used. However, ordering with the TOKEN
function does not always provide the expected results. Use the
TOKEN
function to express a conditional relation on a partition
key column. In this case, the query returns rows based on the token of the partition
key rather than on the value.
The TOKEN
function can also be used to select a range of partitions
for a ByteOrderedPartitioner. Using the TOKEN
function with
ByteOrderedPartitioner will generally yield expected results.
TOKEN
function depends on the type
of the columns used as the argument of the function. The return type depends on the
partitioner in use:- Murmur3Partitioner, bigint
- RandomPartitioner, varint
- ByteOrderedPartitioner, blob