在CASSANDRA中存储JSON对象 [英] Storing JSON object in CASSANDRA

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

问题描述

我想将JSON存储在CASSANDRA数据库中。 JSON的每个字段都应映射到其各自的列。



是否可能?

解决方案



请帮助我。 / div>

答案是相同的在另一篇文章 - Cassandra是没有更多的架构,所以没有开箱即用的解决方案(除非你有一个预定义的json结构)。你可以做的是创建一个第一级的json结构到一个Map< text,text> (如果,我想,你需要的是通过键选择一个条目)

  {
keya :{
keyb:5,
keyc:somestring
},
keyd:3;
}

这将映射到以下映射条目

 < keya,'{keyb:5,keyc:somestring}'> 
< keyd,'3'>

在这种方式下,您可以获取json中任何一级键的内容,搜索后续条目。您还可以将这些键扁平化为如下地图:

 < keya,'{keyb:5, keyc:somestring}'> 
< keya.keyb,'5'>
< keya.keyc:'somestring''>
< keyd,'3'>

您可能还需要在存储原始Json的地图中插入一个自定义条目
以这种方式,您应该能够搜索任何条目,但是您的地图可能更大更多:由于地图是静态类型的,你必须将整数,uuid,float或其他值映射到字符串中。



HTH ,
Carlo


I want to store JSON in CASSANDRA db. Each fields of JSON should be mapped to their respective column.

Is it possible ? if possible then how can I achieve it?.

Please help me guys..

解决方案

The answer is the same given in the other post - Cassandra is no more schema-less so there is no out-of-the-box solution (unless you have a pre-defined json structure). What you could do is to create a first-level json structure into a Map<text, text> (If, as I think, what you need is to select an entry by key)

{
  "keya": {
      "keyb": 5,
      "keyc": "somestring"
   },
  "keyd": 3;
}

This would be mapped into the following map entries

<keya, '{ "keyb": 5, "keyc": "somestring" }'>
<keyd, '3'>

In this way you can get the content for any first-level key in the json but you have to search for subsequent entries. You could also "flatten" your keys into a map like this:

<keya, '{ "keyb": 5, "keyc": "somestring" }'>
<keya.keyb, '5'>
<keya.keyc": ' "somestring" '>
<keyd, '3'>

You might also want insert a custom entry in the map that store the original Json. In this way you should be able to search for any entry but your map could be much bigger than the original json since it's denormalized to perform key based searches. More: since maps are statically typed you have to map integers, uuid, float or whatever into Strings.

HTH, Carlo

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

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