【问题标题】:How to save data to cassandra columfamily using hector with two primary keys?如何使用带有两个主键的赫克托将数据保存到 cassandra columfamily?
【发布时间】:2012-09-21 11:24:05
【问题描述】:

我正在使用 cassandra 1.1.4 和 Hector 1.0.2,我得到了一个映射到 xls 文档的列族定义,我们希望从中存储数据,如下所示:

create table test(
firstId int,
secondId varchar,
somedata varchar,
moredata varchar,
PRIMARY KEY (firstId, secondId));

这是用户需要的,但我如何在 Hector 中进行建模。目前我可以将 Mutator 的 addInsertion(Key k, String cf, HColumn<N,V> sc) 用于单个键,但是有没有办法使用两个主键和不同的数据类型来做到这一点?

感谢任何帮助,即使无法使用 Hector 或其他方式。

提前致谢。

【问题讨论】:

    标签: java cassandra hector


    【解决方案1】:

    Cassandra 是一个键值数据库。它不能有两个键。它可以拥有的是一个复合键,它可以由您的两个所谓的“主键”组成。例如,如果其中之一是 Integer,其中之一是 Long,您将像这样构造键 (Pelops)

    Bytes.composite()
       .addInt(firstKeyVal)
       .addLong(secondKeyVal)
    .build();
    

    使用纯 Thrift,您可以做同样的事情。 实际上,您可能会受到一些限制,因为您无法轻松实现复合键。但是,这是可能的。我正在链接它:

    How to define composite key for a column family and then reference it using Hector?

    【讨论】:

    • 感谢您的回复,我认为这对我很有帮助,因为我不知道该怎么做。
    【解决方案2】:

    使用 CompositeType - How to define composite key for a column family and then reference it using Hector?

    你的行键看起来像:firstId:secondId

    【讨论】:

      猜你喜欢
      • 2013-03-17
      • 2011-12-19
      • 2013-05-01
      • 2013-10-28
      • 2012-05-02
      • 2013-02-23
      • 1970-01-01
      • 2012-11-21
      • 2013-07-10
      相关资源
      最近更新 更多