Reputation: 87
I have next question: is it possible to create column family in cassandra that would look like this below and how to define it's structure:
Users = { //CF
AlexS : { //row key
Address : { //supercolumn
state: "NJ",
country: "US",
phone : { //super column
zip: "00283",
number : { // supercolumn
home: "23756511",
mobile : "23756512"
}
}
}
}
}
Upvotes: 2
Views: 540
Reputation: 8985
Yet another option is to store part or all of the user entity as JSON, since that's how you're representing it. Then if you need to do a reverse lookup, simply write your own index to do so. In that case your key is "AlexS", then you'd have an "Address" column that would contain the JSON representation (or whatever serialization you want to use) of the address data.
Then, if you want to lookup by phone number, you'd have a home-grown index with key=phone number, then a column for each user id.
This is a pretty common approach with Cassandra.
Upvotes: 2
Reputation: 5064
Nested super column within super column for four levels? As far as I know, that is not possible. Because you need to specify by referencing which column family of that current insertion you want it to be. Consider the following, you can have define top level column family to be of type column family super. Then you can have multiple super-columns within this super column family and this supercolumns will have multiple column=value pairs those are called as subcolumns. For example,
list Users;
Using default limit of 100
-------------------
RowKey: AlexS
=> (super_column=Address,
(column=country, value=US, timestamp=1331614891360000)
(column=state, value=NJ, timestamp=1331614891355000))
=> (super_column=number,
(column=home, value=23756511, timestamp=1331614891406000)
(column=mobile, value=23756512, timestamp=1331614891406001))
=> (super_column=phone,
(column=zip, value=00283, timestamp=1331614891396000))
1 Row Returned.
Elapsed time: 21 msec(s).
Upvotes: 7