Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra CompositeType

I've seen in Hector and Cassandra tutorials that there is DynamicCompositeType.

Can anybody elaborate on difference between

   create column family Composite with comparator ='DynamicCompositeType
       (t=>TimeUUIDType,s=>UTF8Type)'
       and default_validation_class=UTF8Type and key_validation_class=UTF8Type;

and

create column family Composite
    with comparator = 'CompositeType(TimeUUIDType,UTF8Type)' 
    and key_validation_class = 'UTF8Type' 
    and default_validation_class = 'UTF8Type'

I've not found it in Cassandra docs

like image 357
danny.lesnik Avatar asked Nov 28 '12 09:11

danny.lesnik


1 Answers

It may help to understand how Cassandra stores data and what composites actually are:

  • All data, regardless of which validator/comparator you use, is stored as bytes. When you specify the validator, you're simply asking Cassandra to make sure those bytes are encoded as you desire. A comparator, by contrast, simply orders the columns based on the natural ordering specific to the encoding you gave it.

  • Composites, then, are just byte arrays with a specific encoding. This encoding is quite simple: for each component, it stores a two-byte length, followed by the byte-encoded component, followed by a termination bit that determines whether it's inclusive or exclusive. Since anything can be stored in byte arrays, you can have disparate component types--but you must know what they are and decode/encode them yourself.

  • To achieve dynamic composites, Hector writes additional type data into the byte array, so that it knows how to decode the bytes when it reads them back out. Static composites have no way to do this as there is no type information.

like image 118
rs_atl Avatar answered Oct 22 '22 10:10

rs_atl