简体   繁体   English

用于复合柱的Cassandra柱系列?

[英]Cassandra column family for Composite Columns?

I am designing the Column Family for our use case in Cassandra. 我正在为Cassandra中的用例设计Column Family。 I am planning to go with Dynamic Column Structure. 我打算使用动态列结构。

Below is my requirement per our use case- 以下是根据我们的用例我的要求-

user-id   column1                                        column2                                     column3
123      (Column1-Value  Column1-SchemaName  LMD)       (Column2-Value Column2-SchemaName  LMD)     (Column3-Value  Column3-SchemaName  LMD)

For each user-id, we will be storing column1 and its value and that value will store these three things always- 对于每个用户ID,我们将存储column1及其值,并且该值将始终存储这三件事-

(Column1-Value   Column1-SchemaName     LMD)

In my above example, I have show only three columns but it might have more columns. 在上面的示例中,我只显示了三列,但可能有更多列。

Now I am not sure, how to store these three thing always at a column value level? 现在我不确定,如何始终将这三件事存储在列值级别? Should I use composite columns at a column level? 我应该在列级别使用复合列吗? if yes, then I am not sure how to make a column family like this in Cassandra. 如果是,那么我不确定如何在Cassandra中创建这样的列族。

Column1-value will be in binary, Column1-SchemaName will be String, LMD will be DateType.

This is what I have so far- 这就是我到目前为止

create column family USER_DATA
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];

Can anyone help me in designing the column family for this? 有人可以帮助我为此设计色谱柱系列吗?

@TechGeeky @TechGeeky

Change the comparator to : 将比较器更改为:

comparator = 'CompositeType(ByteType,UTF8Type,DateType)'

ByteType for Column-Value 列值的ByteType

UTF8Type for Column-SChemaName 列SChemaName的UTF8Type

DateType for LMD LMD的DateType

Be careful though, with this design, querying your data other than by user-id would be hard. 但是请注意,使用这种设计,很难查询用户ID以外的数据。 Especially you would be able to get slices of columns by providing column data (in bytes), if you know them before hand... 特别是,如果您事先知道列数据,则可以通过提供列数据(以字节为单位)来获取列切片...

I would suggest you use CQL3. 我建议您使用CQL3。 If you use Cassandra 1.2+ and CQL3, the following table will result in the partition (row) layout you describe. 如果使用Cassandra 1.2+和CQL3,则下表将导致您描述的分区(行)布局。

CREATE TABLE user_data (
    userid text,
    data bytes,
    schema_name string,
    lmd timestamp,
    PRIMARY KEY (userid, data, schema_name, lmd)
)

You can see the following article for more information on how CQL3 ends up as composite columns under the hood, and makes them much easier to use: 您可以查看以下文章,详细了解CQL3如何最终成为引擎盖下的复合柱,并使它们更易于使用:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts http://www.datastax.com/dev/blog/cql3-for-cassandra-experts

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

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