How to create a complex structure in Cassandra with CQL3

I have a problem with representing a complex data structure in cassandra. Sample JSON data:

{ "A": { "A_ID" : "1111" "field1": "value1", "field2": "value2", "field3": [ { "id": "id1", "name": "name1", "segment": [ { "segment_id": "segment_id_1", "segment_name": "segment_name_1", "segment_value": "segment_value_1" }, { "segment_id": "segment_id_2", "segment_name": "segment_name_2", "segment_value": "segment_value_2" }, ... ] }, { "id": "id2", "name": "name2", "segment": [ { "segment_id": "segment_id_3", "segment_name": "segment_name_3", "segment_value": "segment_value_3" }, { "segment_id": "segment_id_4", "segment_name": "segment_name_4", "segment_value": "segment_value_4" }, ... ] }, ... ] } } 

Only one query will be used: Find by A_ID.

I think that this data should be stored in one TABLE (Column Family) and without serialization / deserialization operations for greater efficiency. How to do this if CQL does not support nested maps and lists?

+6
source share
2 answers

As you will use it as a key / value, you can store it either as JSON, or for more efficient storage of data, for example, BSON or event Protobuf.

I personally saved it in a Protobuf record, since it does not save field names that may be repeated in your case.

+2
source

Cassandra 2.1 adds support for nested structures: https://issues.apache.org/jira/browse/CASSANDRA-5590

The disadvantage of β€œjust saving it as json / protobuf / avro / etc blob” is that you need to read and rewrite the entire block to update any field. Therefore, at least you should pull your top-level fields into Cassandra columns using collections , if necessary.

+8
source

Source: https://habr.com/ru/post/957902/


All Articles