asknsdkns
asknsdkns

Reputation: 55

Cassandra Partition key duplicates?

I am new to Cassandra so I had a few quick questions, suppose I do this:

CREATE TABLE my_keyspace.my_table (
 id bigint,     
 year int,   
 datetime timestamp,    
 field1 int,     
 field2 int,
 PRIMARY KEY ((id, year), datetime))

I imagine Cassandra as something like Map<PartitionKey, SortedMap<ColKey, ColVal>>,

My question is when querying for something from Cassandra using a WHERE, it will be like:

SELECT * FROM my_keyspace.my_table WHERE id = 1 AND year = 4,

This could return 2 or more records, how does this fit in with the data model of Cassandra?

If it really it a Big HashMap how come duplicate records for a partition key are allowed?

Thanks!

Upvotes: 1

Views: 56

Answers (1)

Chris Lohfink
Chris Lohfink

Reputation: 16400

There is a batch of entries in the SortedMap<ColKey, ColVal> for each row, using its sorted nature.

To build on your mental model, while there is only 1 partition key for id = 1 AND year = 4 there are multiple cells:

(id, year) |  ColKey            | ColVal
------------------------------------------
 1, 4      | datetime(1):field1 | 1         \ Row1
 1, 4      | datetime(1):field2 | 2         / 
 1, 4      | datetime(5):field1 | 1         \ 
 1, 4      | datetime(5):field2 | 2         / Row2
...

Upvotes: 3

Related Questions