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

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

问题描述

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

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?.

请大家帮帮我..

推荐答案

答案与另一篇文章中给出的答案相同 - Cassandra 不再是无模式的,因此没有开箱即用的解决方案(除非您有一个预定义的 json 结构).您可以做的是将一级 json 结构创建为 Map;(如果我认为您需要的是按键选择一个条目)

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'>

通过这种方式,您可以获取json中任何一级键的内容,但您必须搜索后续条目.您还可以将您的密钥展平"成这样的地图:

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'>

您可能还想在存储原始 Json 的地图中插入一个自定义条目.通过这种方式,您应该能够搜索任何条目,但您的地图可能比原始 json 大得多,因为它被非规范化以执行基于键的搜索.更多:由于地图是静态类型的,因此您必须将整数、uuid、浮点数或其他任何内容映射到字符串中.

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,卡罗

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

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