在Apache-Cassandra 0.8.2中插入JSON字符串 [英] insert JSON String in Apache-Cassandra 0.8.2

查看:70
本文介绍了在Apache-Cassandra 0.8.2中插入JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道这是在cassandra中插入json字符串的简单方法.假设我有一个像这样的json字符串:{'key1':'val1','key2':'val2'}

Anybody know which is the easy way to insert a json string in cassandra. Suppose I have a json string like this: {'key1':'val1','key2':'val2'}

在MongoDB中,我们可以直接插入json字符串,例如dbobj.insert(jsonstring);.那么在Cassandra中有什么方法可以做到这一点吗?(我正在用Java进行编码)

In MongoDB we can insert directly a json string like dbobj.insert(jsonstring); So is there any way to do like this in Cassandra?(I am coding in java)

推荐答案

至少有3种方法,但这取决于您要实现的目标以及要运行的查询的类型.

There are at least 3 ways, but it depends what you are trying to achieve and what kinds of query you want to run.

您可以将JSON字符串存储为纯字符串/字节和Cassandra列名称(假设您可以将某些内容用作行键).但是,您将无法基于JSON内容进行查询;这将是您在客户端处理的不透明数据.

You could store the JSON string as just a plain string/byte, as a Cassandra column name (assuming there is something you can use as the row key). You won't be able to do queries based on the JSON content, though; this would be opaque data that you process client-side.

您可以在存储之前拆分JSON,以便key1,key2是列名,而val1,val2是对应的列值.同样,您需要将某些东西用作行键.这种方法可以让您检索单个值,并使用二级索引来检索具有特定值的行.

You could split up the JSON before storage, so that key1, key2 are column names and val1, val2 are the corresponding column values. Again, you'd need something to use as a row key. This method would let you retrieve individual values, and use secondary indexes to retrieve rows with particular values.

您甚至可以将key1,key2用作行键,并将val1,val2用作列名.假设您已将JSON中的键值对分组,那么它们大概属于同一实体并且是相关的,因此这不太可能有用,但出于完整性考虑,我会提及它.

You could even use key1, key2 as row keys, with val1, val2 as column names. Given that you have the key-val pairs grouped in JSON, they presumably belong to the same entity and are related, so this is unlikely to be useful, but I mention it for completeness.

编辑添加:如果您的问题实际上是如何将数据完全插入Cassandra ,那么您应该阅读Java客户端的文档,例如 http://wiki.apache.org/cassandra/ClientOptions )

Edited to add: If your question is actually how to insert data into Cassandra at all, then you should read the docs for a Java client such as Hector (there are other options too - see http://wiki.apache.org/cassandra/ClientOptions)

这篇关于在Apache-Cassandra 0.8.2中插入JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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