简体   繁体   English

如何创建无价值的列在Cassandra中通过CQLEngine

[英]How create valueless column In Cassandra By CQLEngine

I have a question about how I can Create valueless column in Cassandra by CQLEngine. 我有一个关于如何通过CQLEngine在Cassandra中创建无价值列的问题。 I mean I want store information in column name instead of column value for some purpose. 我的意思是我希望商店信息以列名而不是列值出于某种目的。 But in CqlEngine you should define you column name before you run your project in model file. 但是在CqlEngine中,您应该在模型文件中运行项目之前定义列名。 Thanks for any help. 谢谢你的帮助。

What your asking about would traditionally be accomplished using the Thrift api and wide rows, defining your own column names. 传统上使用Thrift api和宽行来完成您的询问,定义您自己的列名。 This is not how CQL3 works. 这不是CQL3的工作原理。 If you want to work this way, you can use pycassa, or you can create columns with compound keys. 如果您想以这种方式工作,您可以使用pycassa,或者您可以使用复合键创建列。

For example, with CQL3: 例如,使用CQL3:

create table ratings ( user_id uuid, item_id uuid, rating int, primary key (user_id, item_id));

You'd actually create a wide row, with user_id as the key, and the columns would have the item_id, and the rating would be the value. 您实际上创建了一个宽行,user_id作为键,列将具有item_id,并且评级将是值。 With compound primary keys, rows are transposed into columns. 使用复合主键,行将转换为列。

You might want to read this: http://brianoneill.blogspot.com/2012/09/composite-keys-connecting-dots-between.html 您可能想要阅读此内容: http//brianoneill.blogspot.com/2012/09/composite-keys-connecting-dots-between.html

Ok, first I need to define my column family like this: create table test( user text, itemLiked text, primary key (user,itemLiked)) 好的,首先我需要像这样定义我的列族:create table test(用户文本,itemLiked文本,主键(user,itemLiked))

so the user is row key and itemLiked is Clustering key. 所以用户是行键,itemLiked是群集键。 If I insert values to this cf , cassanndra doesn't create row (internally) for that and the itemliked value will be the name of columns insert into test(user , itemLiked) values ( "user1","Item1"); 如果我向此cf插入值,cassanndra不会为此创建行(内部),itemliked值将是插入test(user,itemLiked)值的列的名称(“user1”,“Item1”); insert into test(user , itemLiked) values ( "user1","Item1"); 插入test(user,itemLiked)值(“user1”,“Item1”);

So cassandra will create two column with name Item1 and Item2 for rowkey user1 this columns hav not any values and as described in this article: http://cassandra.apache.org/doc/cql3/CQL.html in line that: Moreover, a table must define at least one column that is not part of the PRIMARY KEY as a row exists in Cassandra only if it contains at least one value for one such column. 所以cassandra将为rowkey user1创建两个名为Item1和Item2的列,这个列没有任何值,如本文所述: http ://cassandra.apache.org/doc/cql3/CQL.html符合: 此外,一个表必须定义至少一个不属于PRIMARY KEY的列,因为Cassandra中只有一行包含至少一个这样的列的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM