cassandramurmurhash

How to generate Cassandra Token for composite partition key?


My Cassandra ColumnFamily uses the Murmur3Partitioner, and has a composite partition key. With this partitioner I was trying to create a Token, however it seems this token factory only allows Long values. Is it possible to generate these hashes for something like "token(partition_column1, partition_column2)"?


Solution

  • It's supposed to work. In fact, if your partition key is composite, you should be unable to create a token for only a single column. Are you sure that you've defined the composite key properly?

    cqlsh:testks> create table t1(k1 int, k2 text, v text, primary key((k1, k2)));
    cqlsh:testks> insert into t1(k1, k2, v) values (1, 'key', 'value');
    cqlsh:testks> select * from t1;
    
     k1 | k2  | v
    ----+-----+-------
      1 | key | value
    
    (1 rows)
    
    cqlsh:testks> select token(k1) from t1;
    Bad Request: Invalid number of arguments in call to function token: 2 required but 1 provided
    cqlsh:testks> select token(k2) from t1;
    Bad Request: Invalid number of arguments in call to function token: 2 required but 1 provided
    cqlsh:testks> select token(k1, k2) from t1;
    
     token(k1, k2)
    ---------------------
     8064425790465501062
    
        (1 rows)