Cassandra - 数据使用CQL插入嵌套集合类型

时间:2017-08-11 17:49:11

标签: cassandra cql

我需要一些帮助才能在表格中插入数据(使用嵌套集合TYPE)列。

我收到以下错误:

  

来自服务器的错误:代码= 2200 [无效查询]消息="未知字段' icon_id'用户定义类型的值tst_diag_msg_typ"

先谢谢你的帮助!!

这是我正在做的事情:

CREATE TYPE cs_veh.tst_icon_typ (
   icon_id text,
   icon_val text
);


CREATE TYPE cs_veh.tst_diag_msg_typ (
   msg_id text,
   msg_priority int,
   msg_text text,
   IconReason SET <FROZEN<tst_icon_typ>> 
);


CREATE TABLE test_veh_health
(VIN text,
eventtimestamp timestamp,
DiagnosticMessages SET < FROZEN <tst_diag_msg_typ>>,
PRIMARY KEY((VIN),eventtimestamp ))
WITH CLUSTERING ORDER BY (eventtimestamp DESC);
insert into test_veh_health
( VIN,
  eventtimestamp
, DiagnosticMessages 
)
values
('TEST122227751',
 toTimestamp(now())
,{{msg_id : '24.0:ENGINE:MESSAGE', msg_priority : 37, msg_text : 'Oil pressure: Engine off! See owners manual.' }
, { icon_id : 'xx',    icon_val: 'text'}
}
);

1 个答案:

答案 0 :(得分:1)

尝试以下插入声明:

INSERT INTO test_veh_health(vin, eventtimestamp, diagnosticmessages) VALUES (
    'TEST122227751', 
    toTimestamp(now()),
    {
      {
        msg_id : '24.0:ENGINE:MESSAGE', 
        msg_priority : 37, 
        msg_text : 'Oil pressure: Engine off! See owners manual.' , 
        iconreason : { 
          {
            icon_id : 'xx',
            icon_val: 'text'
          }
        }
      }
    }
);

输出:

cqlsh:test> SELECT * FROM test_veh_health ;

@ Row 1
--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------
 vin                | TEST122227751
 eventtimestamp     | 2017-08-11 19:07:27.545000+0000
 diagnosticmessages | {{msg_id: '24.0:ENGINE:MESSAGE', msg_priority: 37, msg_text: 'Oil pressure: Engine off! See owners manual.', iconreason: {{icon_id: 'xx', icon_val: 'text'}}}}

@ Row 2
--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------
 vin                | TEST122227751
 eventtimestamp     | 2017-08-11 18:54:57.519000+0000
 diagnosticmessages | null