有没有办法按照数据类型而不是Cassandra中的字符串来制作聚类顺序?

时间:2013-03-06 22:55:45

标签: cassandra cql3

我使用以下CQL在cqlsh中使用CQL3创建了一个表:

CREATE TABLE test (
    locationid int,
    pulseid int,
    name text, PRIMARY KEY(locationid, pulseid)
) WITH CLUSTERING ORDER BY (locationid ASC, pulseid DESC);

请注意,locationid是一个整数。

然而,在我插入数据并运行select之后,我注意到locationid的升序似乎是基于字符串,而不是整数。

cqlsh:citypulse> select * from test;
 locationid | pulseid | name
------------+---------+------
          0 |       3 | test
          0 |       2 | test
          0 |       1 | test
          0 |       0 | test
         10 |       3 | test
          5 |       3 | test

注意0 10 5.有没有办法让它按实际数据类型进行排序?

谢谢, 艾里

1 个答案:

答案 0 :(得分:3)

在Cassandra中,主键的第一部分是“分区键”。该密钥用于在集群周围分发数据。它以随机方式实现这一点,以实现均匀分布。这意味着您无法通过主键的第一部分进行排序。

你在哪个版本的Cassandra?在最新版本的1.2(1.2.2)中,您使用示例的create语句无效。