2
My Cassandra ColumnFamily使用Murmur3Partitioner,并具有复合分区键。 有了这个分区器,我试图创建一个令牌,但是看起来这个令牌工厂只允许Long值。 是否有可能为“token(partition_column1,partition_column2)”这样的东西生成这些散列?如何为复合分区键生成Cassandra Token?
My Cassandra ColumnFamily使用Murmur3Partitioner,并具有复合分区键。 有了这个分区器,我试图创建一个令牌,但是看起来这个令牌工厂只允许Long值。 是否有可能为“token(partition_column1,partition_column2)”这样的东西生成这些散列?如何为复合分区键生成Cassandra Token?
它应该工作。实际上,如果您的分区键是复合的,则您应该无法仅为单个列创建标记。你确定你已经正确定义了组合键吗?
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)
这是正确的,上面的所有语句都成立。不过,我正在寻找从java api创建这种令牌的方法,而不是执行查询,即使用org.apache.cassandra.dht.Murmur3Partitioner生成可能的令牌范围。 – user3507166
如果您想使用Java API创建它,则必须使用'partitioner.getToken(ByteBuffer)'API。有关详细信息,可以在https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cql3/functions/TokenFct中开始查看CQL'token()'函数的实现.java。 –
工程就像一个魅力,非常感谢! – user3507166