【问题标题】:Create two composite columns with cassandra-cli使用 cassandra-cli 创建两个复合列
【发布时间】:2012-06-29 22:11:55
【问题描述】:

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

这里是使用 CQL 定义表:

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

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

第一个复合的结构是:

CompositeType(Int32Type, BytesType, AsciiType)

它会保存一个整数。

第二个复合的结构是:

CompositeType(Int32Type, BytesType)

并且将持有 BytesType。

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

我不确定如何在创建列族命令中定义第二个复合列。

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

【问题讨论】:

    标签: nosql cassandra


    【解决方案1】:

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

    CompositeType(Int32Type, BytesType, AsciiType)
    

    由于复合材料末尾的“AsciiType”组件,该比较器可以描述您的所有架构。您的列名的这一部分将包含文字字符串“sum”或“uniques”,并且列值将相应地匹配类型。

    使用 json 样式表示法的示例:

    <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
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-12
      • 1970-01-01
      • 2013-12-06
      • 2020-07-24
      • 2012-02-01
      • 1970-01-01
      • 2014-03-03
      • 2012-08-26
      • 1970-01-01
      相关资源
      最近更新 更多