Search code examples
cassandracql

Cassandra ByteOrderedPartitioner


I want to execute some range queries on a table that is structured like:

CREATE TABLE table(

num int,
val1 int,
val2 float,
val3 text,
...
PRIMARY KEY(num)
)

A range query should look like:

SELECT num, val1, val2 FROM table WHERE num>100 AND num<1000;

I read ths post: Performing range queries for cassandra table and now I have problems with using the ByteOrderedPartitoner.

I use the OPSCenter Web Interface and try to create a new cluster. I change the Partitioner and the following error appears:

Error provisioning cluster: A token_map argument of the form {ip: token} is required when not using RandomPartitioner or Murmur3Partitioner

I can not find a token_map argument. What am I doing wrong? What else do I have to do to enable the query?

I hope somebody can help me. Thank you!


Solution

  • What am I doing wrong?

    You are using the Byte Ordered Partitioner. Its use has been identified as a Cassandra anti-pattern...for a while now. Matt Dennis has a slideshare presentation on Cassandra Anti-Patterns, and it contains a slide concerning the BOP: Don't use the Byte Ordered Partitioner

    So while the above slide is meant to be humorous, seriously, do not use the Byte Ordered Partitioner. It is still included with Cassandra, so that those who used it back in 2011 have an upgrade path. No new clusters should be built with the BOP. The (default) Murmur3 partitioner is what you should use.

    As for how to solve your problem with the Murmur3 partitioner, the question/answer you linked above refers to Patrick McFadin's article on Getting Started With Time Series Data Modeling. In that article, there are three modeling patterns demonstrated. They should be able to help you come up with an appropriate data model. Basically, you can order your data with a clustering key and then read it with a range query...just not by your current partitioning key.

    CREATE TABLE tableorderedbynum(
     num int,
     val1 int,
     val2 float,
     val3 text,
     someotherkey text,
    ...
    PRIMARY KEY((someotherkey),num)
    );
    

    Examine your data model, and see if you can find another key to help partition your data. Then, if you create a query table (like I have above) using the other key as your partitioning key, and num as your clustering key; then this range query will work:

    SELECT num, val1, val2 
    FROM tableorderedbynum WHERE someotherkey='yourvalue' AND num>100 AND num<1000;
    

    EDIT 20240215

    Some questions and comments have come up in the last 9 years, so I'll address them here:

    What happens if the text column has non-english characters like japanese or korean?

    Characters from languages like Korean, Japanese, Chinese, etc are actually sorted in the same way as their romanized counterparts. As extended UTF character sets now include these languages, each character has an underlying UTF code as its index, which is also how they will be sorted by.

    This answer and the linked slides provide no concrete reason WHY using BOP is wrong.

    I suppose that I did not. Suffice to say, that one of the goals of Apache Cassandra® is to ensure that data is evenly distributed around the cluster. In a paradigm where partitions are ordered, that becomes problematic. This is because large, alpha-numerically ordered data sets seldom have their values in an even distribution.

    Now, you could certainly argue that uneven nodes are still possible today. However, advances like the Murmur3 partitioner and virtual nodes greatly reduce the likelihood of this happening. As such, this guidance from the cassandra.yaml stands:

    # The default partitioner is the Murmur3Partitioner. Older partitioners
    # such as the RandomPartitioner, ByteOrderedPartitioner, and
    # OrderPreservingPartitioner have been included for backward compatibility only.
    # For new clusters, you should NOT change this value.