Question

I created a table in CQL3 in the cqlsh using the following CQL:

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

Note that locationid is an integer.

However, after I inserted data, and ran a select, I noticed that locationid's ascending sort seems to be based upon string, and not integer.

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

Note the 0 10 5. Is there a way to make it sort via its actual data type?

Thanks, Allison

Was it helpful?

Solution

In Cassandra, the first part of the primary key is the 'partition key'. That key is used to distribute data around the cluster. It does this in a random fashion to achieve an even distribution. This means that you can not order by the first part of your primary key.

What version of Cassandra are you on? In the most recent version of 1.2 (1.2.2), the create statement you have used an example is invalid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top