我使用cygnus在MySQL数据库和Cosmos中存储数据。 在宇宙中存储数据工作正常,但在MySQL中存储时,特别是使用属性" cygnusagent.sinks.mysql-sink.attr_persistence = column"而不是" cygnusagent.sinks.mysql-sink.attr_persistence = row"数据没有存储,我在水槽日志中遇到了一些错误。
由于在使用column属性时需要先创建表(更多信息:https://github.com/telefonicaid/fiware-cygnus/blob/master/doc/design/OrionMySQLSink.md#important-notes-regarding-the-persistence-mode),我创建表:
CREATE TABLE def_servpath_sensorreading4_sensorreading(systemid int,value float, sensorid int, nodeid int);
DESCRIBE def_servpath_sensorreading4_sensorreading(systemid int,value float, sensorid int, nodeid int);
mysql> DESCRIBE def_servpath_sensorreading4_sensorreading;
+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| systemid | int(11) | YES | | NULL | |
| value | float | YES | | NULL | |
| sensorid | int(11) | YES | | NULL | |
| nodeid | int(11) | YES | | NULL | |
+----------+---------+------+-----+---------+-------+
4 rows in set (0.00 sec)
这是水槽日志:
11 Aug 2015 11:40:31,977 INFO [SinkRunner-PollingRunner-DefaultSinkProcessor] (com.telefonica.iot.cygnus.sinks.OrionMySQLSink.persist:240) - [mysql-sink] Persisting data at OrionMySQLSink. Database: def_serv, Table: def_servpath_sensorreading3_sensorreading, Timestamp: 2015-08-11T08:40:31.969, Data (attrs): {systemid=1, value=29.2, sensorid=2, nodeid=1}, (metadata): {sensorid_md=[], systemid_md=[], value_md=[], nodeid_md=[]}
11 Aug 2015 11:40:31,978 WARN [SinkRunner-PollingRunner-DefaultSinkProcessor] (com.telefonica.iot.cygnus.sinks.OrionSink.process:182) - Bad context data (Unknown column 'systemid' in 'field list')
11 Aug 2015 11:40:31,978 INFO [SinkRunner-PollingRunner-DefaultSinkProcessor] (com.telefonica.iot.cygnus.sinks.OrionSink.process:193) - Finishing transaction (1439278647-655-0000000005)
11 Aug 2015 11:40:32,369 INFO [SinkRunner-PollingRunner-DefaultSinkProcessor] (com.telefonica.iot.cygnus.sinks.OrionHDFSSink.persist:356) - [hdfs-sink] Persisting data at OrionHDFSSink. HDFS file (def_serv/def_servpath/sensorreading3_sensorreading/sensorreading3_sensorreading.txt), Data ({"recvTime":"2015-08-11T08:40:31.969Z","nodeid":"1", "nodeid_md":[],"sensorid":"2", "sensorid_md":[],"systemid":"1", "systemid_md":[],"value":"29.2", "value_md":[]})
11 Aug 2015 11:40:32,858 INFO [SinkRunner-PollingRunner-DefaultSinkProcessor] (com.telefonica.iot.cygnus.sinks.OrionSink.process:193) - Finishing transaction (1439278647-655-0000000005)
我得到以下错误:
错误的上下文数据(未知列' systemid' in'字段列表')
我是否需要在与元数据相关的表中创建更多列?我是否正确创建了表格?
提前致谢。
答案 0 :(得分:0)
是的,文档的this部分详细说明了必须为每个属性添加关于元数据的附加列(通过使用_md
填充属性的名称)。然而,没有给出一个例子(有待改进的地方,顺便说一句),所以这里(根据你的具体情况量身定做):
create table def_servpath_sensorreading4_sensorreading(recvTime text, systemid int, systemid_md text, value float, value_md text, sensorid int, sensorid_md text, nodeid int, nodeid_md text);
属性名称与表中的字段匹配非常重要。我的意思是,您的实体必须具有名为systemid
的属性;如果您的属性名为system_id
,那么它也必须是字段名称(作为元数据字段system_id_md
)。
您可以看到,有一个关于接收时间(recvTime
)的附加列,因为每次收到通知时Cygnus都会保留这样的值。
关于表名,您已经完美地编写了它:它必须是通知的FIWARE服务路径,实体ID和实体类型('_'作为连接字符)的串联。这样的表必须存在于名为通知的FIWARE服务的数据库中。