Cassandra CompositeType
Asked Answered
M

2

6

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

Misdemean answered 28/11, 2012 at 9:7 Comment(0)
H
6

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.

Haarlem answered 28/11, 2012 at 14:43 Comment(0)
T
0

With static composite CF every column will have a same type, where as with dynamic CCF every column can have different data types.

If you are sure about what type of data goes inside CF better to stick with static definition else use dynamic CF.

Tutuila answered 28/11, 2012 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.