如何从CQL表中的JSON列中选择键作为列?

问题描述 投票:0回答:1

我在CQL中创建了下表:

CREATE TABLE new_table ( idRestaurant INT, restaurant map<text,varchar>, InspectionDate date, ViolationCode VARCHAR, ViolationDescription VARCHAR, CriticalFlag VARCHAR, Score INT, GRADE VARCHAR, PRIMARY KEY (InspectionDate )) ;

然后,我已经通过jar插入数据,我得到的restaurant column值就像json/dictionary

select restarutant from new_table;就像以下结果:enter image description here

在正常的SQL中,选择json列的键值应该是select json_col.key from table但是这对CQL不起作用,我如何选择JSON的键值作为列或WHERE条件过滤?

非常感谢

json cassandra cql
1个回答
0
投票

我最好将表的架构更改为以下内容,而不是使用map:

CREATE TABLE new_table (
  idRestaurant INT, 
  restaurant_key text,
  restaurant_value text,
  InspectionDate date, 
  ViolationCode VARCHAR,
  ViolationDescription VARCHAR, 
  CriticalFlag VARCHAR, 
  Score INT, 
  GRADE VARCHAR, 
  PRIMARY KEY (InspectionDate, restaurant_key )) ;

然后你可以选择基于restaurant_key的单个行和查询,如:

select * from new_table where idRestaurant = ? and restaurant_key = ?

或者为餐厅选择一切:

select * from new_table where idRestaurant = ?
© www.soinside.com 2019 - 2024. All rights reserved.