如何使用列中的 JSON 子对象从 Cassandra 中进行选择?

问题描述

下面是一个条目在 Cassandra 中的样子:

id | address                     | age | family  | name | siblings
-----------------------------------------------------------------
 1 | {'city': 'c1','rue': 'r1'} |  23 |      si |   si | {'b','d'}

我想根据 select 列中作为 JSON 子代的城市address

我不确定以下陈述是否正确:

select address from Persons address.city='f';  
select address.city from Persons ;   

解决方法

不幸的是,这不能在 Cassandra 中完成(至少目前是这样)。

一种可能的选择是将您的模型更改为类似

 id | city | rue | age | family  | name | siblings
----+------+-----+-------------------------------
  1 |   c1 |  r1 |  23 |      si |   si | {'b','d'}

然后你就可以执行查询了:

select json city,rue from addresses where city = 'c1';  

在结果中实现“即用型”json:

 [json]
-----------------------------
{"city": "c1","rue": "r1"}