2017-08-11 106 views
2

我需要一些幫助將數據插入表(嵌套收集TYPE)列中。Cassandra - 使用CQL將數據插入嵌套收集類型

我收到以下錯誤:

Error from server: code=2200 [Invalid query] message="Unknown field 'icon_id' in value of user defined type 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

嘗試下面的插入語句:

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