Reputation: 433
I try to build a backend for quiz game statistics : I want to know recognition percent for each image globally and recognition percent of images by country.
Currently datamodel is :
TABLE results ( country text, percent float, image_id text, fail int, ok int, shown int, PRIMARY KEY (country, percent, image_id) );
I can query results by country, but I can't get global results(images with higher percent).
Any hint ?
Upvotes: 2
Views: 125
Reputation: 38
You need two CFs.
Another way is to use ordering partitioning and use keys of CompoteType, so your key is not PRIMARY KEY (country, percent, image_id) but PRIMARY KEY ((country, percent, image_id)).
You also need another column, image_id and you could put a secondary index on that image_id so that you can do queries where image_id=x
Upvotes: 0
Reputation: 6418
It's possible to define "TOTAL" country that will hold sum of stats for all countries.
P.S. Making percent
part of primary key doesn't seem to be a good idea due to eventual consistency in cassandra: it won't be possible to do an atomic update of percent
field.
I think there are two possible situations: either the data set would be small enough - then any SQL DB with secondary index on the percent
field will do job better than cassandra, or there would be too much data for SQL DB - then Cassandra with this data model won't work either, only the map/reduce of partial counts will do.
Upvotes: 2