2013-11-04 21 views
0

选择适合卡桑德拉“表”正确的模式,我们正在努力存储大量的属性为表内的特定PROFILE_ID(使用CQL3),并不能完成我们的头周围哪种方法是最好的:在CQL3

一。 create table mytable(profile_id,a1 int,a2 int,a3 int,a4 int ... a3000 int)主键(profile_id);

b。创建很多表,例如。 create table mytable_a1(profile_id,value int)主键(profile_id); create table mytable_a2(profile_id,value int)主键(profile_id); ... create table mytable_a3000(profile_id,value int)主键(profile_id);

c。 create table mytable(profile_id,a_all text)主键(profile_id); (1,“a1:1,a2:5,a3:55,.... a3000:5”)插入到mytable(profile_id,a_all)中; ,并且只存储a_all中的3000个“列”,如: ;

d。以上都不是

的类型,我们会在这个表上运行查询的: SELECT * FROM MYTABLE其中PROFILE_ID在(1,2,3,4,5423,44)

我们尝试第一种方法并且查询保持超时,有时甚至杀死cassandra节点。

回答

2

答案是使用聚类列。群集列允许您创建可用于保存属性名称(col名称)及其值(col值)的动态列。

表将

create table mytable ( 
    profile_id text, 
    attr_name text, 
    attr_value int, 
    PRIMARY KEY(profile_id, attr_name) 
) 

这允许你添加像

insert into mytable (profile_id, attr_name, attr_value) values ('131', 'a1', 3); 
insert into mytable (profile_id, attr_name, attr_value) values ('131', 'a2', 1031); 
..... 
insert into mytable (profile_id, attr_name, attr_value) values ('131', 'an', 2); 

该刀片将是最佳的解决方案。

因为你再要做到以下几点 “的类型,我们会在这个表上运行的查询:从mytable的选择*其中PROFILE_ID在(1,2,3,4,5423,44)”

这需要引擎盖下的6个查询,但cassandra应该能够很快做到这一点,特别是如果您有多节点集群。

此外,如果您使用DataStax Java驱动程序,则可以在群集上异步并发地运行这些请求。

有关数据建模和DataStax Java驱动程序的更多信息,请查看DataStax的免费在线培训。它值得一看 http://www.datastax.com/what-we-offer/products-services/training/virtual-training

希望它有帮助。