Cassandra:创建分区表,但主键中不包含分区列名 [英] Cassandra: Create a partitioned table without including the partitioned column name in primary key

查看:179
本文介绍了Cassandra:创建分区表,但主键中不包含分区列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个分区表而不在主键中包含分区列名。

我不知道如何创建表的线索,因为大多数示例在主键中声明了群集列。部分。
我不确定它是否可以在Cassandra中使用,因此需要寻求帮助。

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);

我的要求是

该表应能够将数据存储为年/月/日分区,并按 city 的排序顺序存储。

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

推荐答案

基于注释,我假设您存储数据的方式就是计划获取数据的方式。基于此假设,我提出了以下表格结构;
创建表crossfit_gyms_by_city(
year int,
month int,
day int,
城市文字,
country_code文字,
state_province文本,
gym_name文本,
主键((年,月,日),城市));

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));

因此您的数据将根据年,月,日&您的群集列为 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

我也建议您完成本课程,将帮助您满足数据建模要求
https://academy.datastax .com / resources / ds220?path = developer

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

这篇关于Cassandra:创建分区表,但主键中不包含分区列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆