使用cassandra-cli创建两个复合列 [英] Create two composite columns with cassandra-cli

查看:293
本文介绍了使用cassandra-cli创建两个复合列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的列家庭需要两个复合列,关键数据类型是BytesType。

My column family needs two composite columns, the key data type is BytesType.

这里是使用CQL的表的定义:

Here is the definition of table using CQL:

CREATE TABLE stats (
      gid          blob,
      period       int,
      tid          blob, 
      sum          int,
      uniques      blob,
      PRIMARY KEY(gid, period, tid)
     );

我想做的是创建列族,但使用Cassandra CLI。这是我的镜头。

What I want to do is to create the column family but with Cassandra CLI. Here is my shot.

第一个复合体的结构是:

The structure of the first composite is:

CompositeType(Int32Type, BytesType, AsciiType)

,它将保存一个整数。

第二个复合体的结构是:

The structure of the second composite is:

CompositeType(Int32Type, BytesType)

并将保存BytesType。

and will holds BytesType.

create column family stats with comparator = 'CompositeType(Int32Type, BytesType, AsciiType)';

我不知道如何在create column family命令中定义第二个复合列。

I'm not sure how to define the second composite column in create column family command.

当然,我假设使用CQL创建的表将生成两个复合列。

Of course I'm assuming that the table created with CQL will generate two composite columns.

推荐答案

Cassandra中的列族只能有一个比较器。这意味着您也只能在列系列中使用一种类型的复合列。您使用的CQL语句创建的表实际上将使用您提到的第一个复合类型比较器:

You can only have one comparator on a column family in cassandra. This means you can also only have one type of composite column in column family. The table created by the CQL statement you used would actually use the first composite type comparator that you mention:

CompositeType(Int32Type, BytesType, AsciiType)

比较器可以描述所有的模式,因为AsciiType的复合。您的列名称的此组件将包含字符串sum或uniques,并且列值将相应匹配类型。

That comparator can describe all of your schema because of the 'AsciiType' component at the end of your composite. This component of your column names will contain the literal string 'sum' or 'uniques', and the column value will match the type accordingly.

使用json样式符号:

An example using a json style notation:

<bytes> : {                               # a row key in your stats column family
    (100, <bytes>, "sum") : 100,          # one column in your row
    (100, <bytes>, "uniques") : <bytes>,  
    (200, <bytes>, "sum") : 200,
    (200, <bytes>, "uniques") : <bytes>
}
<bytes> : {                               # another row in the cf
    ...
}

这篇关于使用cassandra-cli创建两个复合列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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