The protobuf message 'sessionproto' that I receive has a field that is recursive.
itemrelationproto references itemgroupproto and itemgroupproto references itemrelationproto .
How do I define a data model in Cassandra to store this data?
Thanks.
message itemrelationproto {
optional string id = 1;
optional itemgroupproto itemgroup = 2;
}
message itemgroupproto {
optional string id = 1;
optional string displayname = 2;
repeated itemrelationproto itemrelations = 3;
}
message sessionproto {
optional string sessionid = 1;
optional string displayname = 3;
repeated itemrelationproto itemrelations = 4;
}
create type itemrelationproto (
id text,
itemgroup frozen<itemgroupproto>
);
create type itemgroupproto (
id text,
displayname text,
itemrelations set<frozen<itemrelationproto>>
);
create table sessionproto (
sessionid text,
displayname text,
itemrelations set<frozen<itemrelationproto>,
primary key (sessionid)
);
Cassandra is not a relational database as you cannot store items that reference each others. So there is no way of doing recursion in Cassandra.
But what you are trying to do is to define a type recursively which is not currently possible. The solution I suggest is to convert your proto into a byte array or json or whatever else and to store it in a
text
orblob
field. Another solution is to create multiple tables and to store each message separately but you will need several requests to select the wholesessionproto
.