cassandra - composite column keys & composite row keys -
i'm trying understand concept of composite column key & composite row key unable it. think it's used getting range of values can't use timestamp column cluster key purpose ? use case, advantages, disadvantages & implementation. please explain using cql 3.
composite column key: http://i.stack.imgur.com/qlbok.png
composite row key: http://i.stack.imgur.com/xa6hz.png
maybe confuse both terms refers how cassandra stores compounds primary keys. i'll explain how composite keys works , how stored physically cassandra 2.0 , cql3.
cassandra stores logical rows same partition key single physical wide row. partition key divided in (partition_key, clustering_key).
- partition_key: identifies row in cassandra. registers same partition_key go same machine , store together. can compound partition_key.
- clustering_key: keep data same partition_key ordered. can set multiple clustering keys separated commas.
imagine have table purchase definition:
create table purchase( user text, item text, time timestamp, primary key ((user, item), time) );
and data
john car 09/01/14... john car 09/05/13... john house 09/07/11... penny laptop 09/08/08... penny laptop 09/03/11... rachel tv 09/01/09...
cassandar store data
john || car || 09/05/13 - 09/01/14 john || house || 09/07/11 penny || laptop || 09/08/08 - 09/03/11 rachel || tv || 09/01/09
if want retrieve cars john bought can assure 2 registers stored , ordered time.
for querys have set partition key fields ( = ) , can if want compare order of clustering keys ( < or > ).
examples:
- select * purchase user='penny' , item='laptop'. return 2 registers.
- select * purchase user='john' , item='car' date 01/01/14. return 1 register.
hope helps.
Comments
Post a Comment