json - 如何从 CQL 表中的 JSON 列中选择键作为列?
问题描述
我在 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;
就像下面的结果:
在用于选择 json 列的键值的普通 SQL 中应该是select json_col.key from table
但这不适用于 CQL,我如何选择 JSON 的键值作为列或用于 WHERE 条件过滤?
太感谢了
解决方案
我最好将表的架构更改为以下,而不是使用地图:
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
with 查询选择任一行,例如:
select * from new_table where idRestaurant = ? and restaurant_key = ?
或选择餐厅的所有内容:
select * from new_table where idRestaurant = ?
推荐阅读
- prolog - Eclipse CLP 标记:排除排列
- c++ - 当 libhdfs hdfsRename 将返回 -1
- ios - 错误值可选(错误域=kCLErrorDomain 代码=8“(空)”)
- java - 完整执行时间多线程java
- angular - 更改路线后如何保存表格过滤器/页面?
- c# - 在数据库优先的应用程序中验证数据库模式?
- ios - 在带有触摸指示器且无光标的设备或模拟器上录制 iOS 应用程序的视频
- git - Github - 在合并后清理分支作为拉取请求的一部分
- javascript - 无法加载资源错误:服务器响应状态为 404(未找到)
- ios - 由于未捕获的异常“RLMException”而终止应用程序,原因:“对象已被删除或无效。”