Question

I am trying to model the following data model in Cassandra:

Business - primary key : BusinessId

Has Many Reviews - primary key : ReviewId
   - Review 1
        - Body
        - Rating
   - Review 2
        - Body
        - Rating 
   and so on
Has an Address
  - State
  - City
  - Zip
Has Business Hours
  - Monday Hours
  - Tuesday Hours
  and so on
Has Offers
  - Offer1
  - Offer2
  and so on

I want to be able to extract all this information using one query, i.e. I want to store this in one business row. How can I do this? Essentially, I have many child entities that I want to store along with the parent business entity. From what I understand about composite keys, you can only have one composite key (ex) businessId:ReviewId to model reviews), but how do I store all these entities in one single row to efficiently retrieve all the business details in one query.

My second question is regarding updates. Suppose only one of these entities (Reviews) gets updated frequently. The other entities mostly remain static. Is it advisable to separate the reviews from this giant business row, or can I update reviews without getting the entire business row in memory?

Was it helpful?

Solution

You can accomplish what you're trying to do using a traditional schema-less Thrift-based query model. Your data model could look like this:

Key: ReviewID {
  Review:1:Body = ""
  Review:1:Rating = 1
  Review:2:Body = ""
  Review:2:Rating = 1
  Address:1:City = ""
  Address:1:State = ""
  Address:1:Zip = ""
  Hours:1:Monday = ""
  Hours:1:Tuesday = ""
  Offer:1:[fieldName] = ""
  Offer:2:[fieldName] = ""
}

The schema for this would be Composite(Utf8Type, IntegerType, Utf8Type) with whatever key type matches your ReviewID and whatever value type matches your values (can be bytes if you have disparate types).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top