在Cassandra中存储值列表 [英] Storing a list of values in Cassandra

查看:126
本文介绍了在Cassandra中存储值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的一些答案与旧版本的Cassandra有关。这种问题的正确答案取决于您使用的Cassandra的版本。

Some of the answers to this question deal with older versions of Cassandra. The correct answer for this kind of problem depends on the version of Cassandra you are using.

我有一个配置文件列族并希望在每个配置文件中存储一个技能列表。我不知道这是如何在Cassandra中典型地完成。一个选择是存储序列化的 Thrift 或protobuf,但我不想这样做,因为我相信Cassandra不具备这些格式的知识,因此数据存储中的数据不会通过CQL从命令行读取或查询。我想到的另一个解决方案是使用一个超级列,并把技能作为关键与空值:

I have a profile column family and want to store a list of skills in each profile. I'm not sure how this is typically accomplished in Cassandra. One option would be to store a serialized Thrift or protobuf, but I'd prefer not to do this as I believe Cassandra doesn't have knowledge of these formats, and so the data in the datastore would not not human readable or queryable via CQL from the command line. The other solution I thought of would be to use a super column and put the skill as the key with a null value:

skills: {
  'java': '',
  'c++': '',
  'cobol': ''
}

这是一个处理Cassandra列表的好方法吗?我想象有一些我不知道的成语。我正在使用 Astyanax 客户端库,它仅支持复合列,而不支持super
列,因此上面提出的解决方案在这种情况下看起来很尴尬。虽然我仍然有一些麻烦理解复合列,因为它们似乎还没有完全记录。

Is this a good way of handling lists in Cassandra? I imagine there's some idiom I'm not aware of. I'm using the Astyanax client library, which only supports composite columns instead of super columns, and so the solution I proposed above would seem quite awkward in that case. Though I'm still having some trouble understanding composite columns as they seem not to be completely documented yet. Would this solution work with composite columns?

推荐答案

这个解决方案是在Cassandra 1.2版本发布之前的,它提供了完全不同的功能用于处理列表。如果您使用Cassandra 1.2 +,答案可能不合适。

This answer dates to before the release of Cassandra version 1.2, which provided substantially different functionality for handling lists. The answer might be inappropriate if you are using Cassandra 1.2+.

如邮件列表中所述,对我来说工作得很好,是存储一个列技能,值是一个序列化的JSON字符串。

As mentioned on the mailing list, my preference which has worked very well for me, is to store a single column "skills" with the value being a serialized JSON string.

真的归结于你对技能的使用模式。

Really comes down to the usage patterns you have for "skills".


  • 如果技能仅针对每个用户的CRUD,这是很好的。

  • 如果您希望能够搜索具有cobol技能的所有用户,那么我仍然会推荐此方法,并且使用另一个是技能:cobol有一列UUID和值的时间戳或类似的东西...

  • 我确定Pig / Hadoop集成到你的cassandra节点,你还可以非常高兴地查询所有拥有x,y和z的用户生成新数据以支持其他用例。

  • If "skills" are just for CRUD on a per user basis, this is fine.
  • If you want to be able to search for all users that have a skill of "cobol", then I would still recommend this approach and have another row that is skill:cobol that has a column of UUID and a value of timestamp or something similar ...
  • I'm sure with Pig/Hadoop integration to your cassandra nodes, you could also still quite happily query all of the users that have x,y and z to generate new data to support additional use cases.

这篇关于在Cassandra中存储值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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