How can I pull in a range of Composite columns with CQL3?
Consider the following:
CREATE TABLE Stuff (
a int,
b text,
c text,
d text,
PRIMARY KEY (a,b,c)
);
In Cassandra what this effectively does is creates a ColumnFamily with integer rows (values of a) and with CompositeColumns composed of the values of b and c and the literal string 'd'. Of course this is all covered up by CQL3 so that we will think that we're inserting into individual database rows... but I digress.
And consider the following set of inputs:
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','P','whatever0');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','Q','whatever1');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','R','whatever2');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','S','whatever3');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','T','whatever4');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','P','whatever5');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','Q','whatever6');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','R','whatever7');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','S','whatever8');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','T','whatever9');
In my current use case, I want to read all of the values of Stuff, n
values at a time. How do I do this? Here's my current take using n=4
:
SELECT * FROM Stuff WHERE a=1 LIMIT 4;
And as expected I get:
a | b | c | d
---+---+---+-----------
1 | A | P | whatever0
1 | A | Q | whatever1
1 | A | R | whatever2
1 | A | S | whatever3
The trouble that I run into is how do I get the next 4? Here is my attempt:
SELECT * FROM Stuff WHERE a=1 AND b='A' AND c>'S' LIMIT 4;
This doesn't work because we've constrained b to equal 'A' - which is a reasonable thing to do! But I've found nothing in the CQL3 syntax that allows me to keep iterating anyway. I wish I could do something like:
SELECT * FROM Stuff WHERE a=1 AND {b,c} > {'A','S'} LIMIT 4;
How do I achieve my desired result. Namely, how do I make CQL3 return:
a | b | c | d
---+---+---+-----------
1 | A | T | whatever0
1 | B | P | whatever1
1 | B | Q | whatever2
1 | B | R | whatever3