Cassandra: Create a partitioned table without including the partitioned column name in primary key

China☆狼群 提交于 2020-02-06 07:55:47

问题


I want to create a partitioned table without including the partitioned column name in primary key.
I am not getting any clue how to create it because most of the examples declaring the clustering column in the primary key section. I am not sure whether it is doable in Cassandra or not hence seeking some help.

CREATE TABLE crossfit_gyms_by_city (  
 country_code text,  
 state_province text,  
 city text,  
 gym_name text,
 year int,
 month int,
 day int);

My requirement is:
The table should be able to store the data as Year/Month/Day partition and by the sorting order of city.


回答1:


Based on the comments, I am assuming the way you store data is how you plan to fetch it. Based on this assumption I propose the below table structure; CREATE TABLE crossfit_gyms_by_city ( year int, month int, day int, city text, country_code text, state_province text, gym_name text, PRIMARY KEY ((year, month, day), city));

So your data will be partition based on year,month,day & your clustering column would be city so the data is sorted by city

Also I would suggest going through this course which will help you out with your data modelling requirements https://academy.datastax.com/resources/ds220?path=developer



来源:https://stackoverflow.com/questions/59872964/cassandra-create-a-partitioned-table-without-including-the-partitioned-column-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!