问题
I've a problem which has been bothering me from quite while now. I'm scaling it down for simplification.
I've a column family in Cassandra defined as:
CREATE TABLE "Test" (
key text,
column1 text,
value text,
PRIMARY KEY (key, column1)
)
If I run a query in CQL as:
select * from "Test" where key in ('12345','34567');
It gives me something like:
key | column1 | value
-----------------------+---
12345 | 764 | 764
12345 | 836 | 836
12345 | 123723 | 123723
12345 | 155863 | 155863
key | column1 | value
-----------------------+---
34567 | 159144 | 159144
34567 | 159869 | 159869
34567 | 160705 | 160705
Now my question is how can I limit my results to 2 rows max per record. I tried to use the following but didn't work.
select FIRST 10 'a'..'z' from "Test" where key in ('12345','34567');
- Not available in latest CQL version.
select * from "Test" where key in ('12345','34567') limit 2;
-Only limits total number of rows, not per record
回答1:
There is no way to have this type of limit in CQL3. You have to run a separate query for each partition.
If query latency is not an issue for you, you always can install SparkSQL/Hive on top of your Cassandra database for complex analytical queries like the one in your original question. You even can cache the result of these queries.
来源:https://stackoverflow.com/questions/30568525/limiting-columns-per-record-in-cql