Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cql3 query with more than 1 EQ restriction and ORDER BY

Tags:

cassandra

cql3

using CF:

CREATE TABLE history (
  domain text,
  iid text,
  timeid timeuuid,
  data text,
  comments text,
  PRIMARY KEY (domain, iid, timeid)
);

I'd like to query it like this:

select domain, iid, timeid, data, comments from mappings
where domain = 'a' and iid = 'b'  order by timeid desc;

But it fails with the following error (cassandra 1.1.5):

Bad Request: Order by currently only support the ordering of columns following their declared order in the PRIMARY KEY

Am I doing it wrong? What could be the workaround? Thx

PS I got it working with the single EQ restriction and ORDER BY but I need at least 2 restrictions and order by.

like image 475
Ivan Velykorodnyy Avatar asked Nov 08 '12 08:11

Ivan Velykorodnyy


1 Answers

You can change 'order by' column to second column in primary key:

select * from history where domain = 'a' and iid = 'b' order by iid desc;

It is a bit confusing because you restrict iid with equality, but it works - you will get your result sorted by timeid.

I believe this is because iid and timeid form one composite column and when you order by iid in descending order, it orders all composite column components including timeid.

like image 96
Dmitry Shohov Avatar answered Nov 06 '22 16:11

Dmitry Shohov