Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Cassandra / CQL3 column family have a composite partition key?

Tags:

cassandra

CQL 3 allows for a "compound" primary key using a definition like this:

CREATE TABLE timeline (
    user_id varchar,
    tweet_id uuid,
    author varchar,
    body varchar,
    PRIMARY KEY (user_id, tweet_id)
);

With a schema like this, the partition key (storage engine row key) will consist of the user_id value, while the tweet_id will be compounded into the column name. What I am looking for, instead, is for the partition key (storage engine row key) to have a composite value like user_id:tweet_id. Obviously I could do something like key = user_id + ':' + tweet_id in my application, but is there any way to have CQL 3 do this for me?

like image 384
mithrandi Avatar asked Dec 18 '12 17:12

mithrandi


2 Answers

Actually, yes you can. That functionality was added in this ticket:

https://issues.apache.org/jira/browse/CASSANDRA-4179

The format for you would be:

CREATE TABLE timeline (
    user_id varchar,
    tweet_id uuid,
    author varchar,
    body varchar,
    PRIMARY KEY ((user_id, tweet_id))
);
like image 170
nickmbailey Avatar answered Oct 13 '22 00:10

nickmbailey


Until 1.2 comes out, the answer is no. The partition key will always be the first component. As you said, the way to do this would be to create the composite key yourself. You shouldn't shy away from this as it's actually quite common.

like image 31
rs_atl Avatar answered Oct 12 '22 23:10

rs_atl