Schema design for top ranked post query in cassandra -
i have requirement need find top ranked pictures in chronological order city. came below schema
create table top_picture( picture_id uuid, city text, rank int, date timestamp, primary key (city,date,rank) ) clustering order (date desc,rank desc);
it solve problem extent (apart duplicates) executing following query
select * top_picture city='san diego';
. if same picture_id inserted in same day duplicate entries picture_id not part of partition key. can not add partitioning key because won't able make simple selection query above need provide picture_id selection query , won't give top pics city.
did came accross type of schema before or other recommended ways it.
it sounds want 2 views of data. in 1 view want top ranked pictures , in other view want picture_id unique.
so have 2 tables, 1 has picture_id primary key , other have shown.
when have picture insert, first try insert picture_id table using if not exists clause on insert statement. if insert fails, duplicate , not insert top_picture table.
in cassandra 3.0 there going support materialized views this, have manage both tables in application code.
Comments
Post a Comment