在CASSANDRA中存储JSON对象

编程入门 行业动态 更新时间:2024-10-26 02:32:16
本文介绍了在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对象

本文发布于:2023-10-23 06:12:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520028.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   CASSANDRA   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!