我无法插入JSON并将数据更新到我的Cassandra表。
我有一个具有以下结构的表:
CREATE TYPE keyspace.connected_hw (
connected_element text,
support_list frozen<list<text>>
);
CREATE TABLE keyspace.sample_table (
id text,
name text,
connected_items frozen<keyspace.connected_hw>
)
我的插入脚本如下所示:
INSERT INTO keyspace.sample_table JSON '
{
"id": "12345",
"name": "object 1",
"connected_items": [
{
"connected_element": "56789",
"support_list": ""
}
]
}
'
运行后,我收到以下错误:
Error decoding JSON value for connected_items: Expected a map, but got a ArrayList :
我试图在没有&#39; connected_items&#34;的情况下插入其他字段。先列出,然后再更新:
INSERT INTO keyspace.sample_table JSON '
{
"id": "12345",
"name": "object 1",
}
'
这一直有效,直到我尝试更新“connected_items&#39;与
UPDATE keyspace.sample_table
SET connected_items = [{connected_element:'56789',support_list:['type1','type2']}]
where id='12345'
运行此操作后,我收到以下错误:
InvalidQueryException: Invalid list literal for connected_items of type frozen<connected_hw>
答案 0 :(得分:1)
您要将connected_items
声明为connected_hw
类型,但您要将值作为'connected_hw'列表插入,support_list
列表中的text
不仅仅是text
}}
您可以更改插入/更新格式,如下所示:
INSERT INTO sample_table JSON '{"id": "12345", "name": "object 1", "connected_items": { "connected_element": "56789", "support_list": ["a","b"] } }' ;
并且
UPDATE sample_table SET connected_items = {connected_element:'56789',support_list:['type1','type2']} where id='12345' ;
或者将connected_items的类型更改为connected_hw列表
ALTER TABLE sample_table DROP connected_items ;
ALTER TABLE sample_table ADD connected_items list<frozen <connected_hw>>;