问题
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