Cassandra 存储对象列表
Cassandra store list of objects
我需要在 cassandra 中存储地图列表。那可能吗?
这是我的数据的 json 表示:
{
"deviceId" : "261e92b8-91af-40da-8ba4-c39d821472ec",
"sensors": [
{
"fieldSensorId": "sensorID",
"name": "sensorName",
"location": "sensor location",
"unit": "value units",
"notes": "notes"
},
{
"fieldSensorId": "sensorID 2",
"name": "sensorName 2",
"location": "sensor location 2",
"unit": "value units",
"notes": "notes"
}
]
}
CQL:
CREATE TABLE device_sensors (
device_id text,
sensors list<frozen <map<text,text>>>,
time timeuuid,
PRIMARY KEY (device_id)
)
我仍然无法插入任何数据。在 cassandra 中存储此类数据的正确方法是什么?稍后我需要查询传感器列表
创建传感器 table 并使用 sensor > 引用传感器是否更明智?
我认为问题在于您在 CQL 中将 devide_id
声明为 text
,但是您在源代码中声明了 UUID
,并且 Spring 映射尝试插入数据时将其转换为相应的类型。您可以尝试将 @CassandraType(type = Name.TEXT)
添加到 deviceId
声明中吗?您还可以删除 @Column
声明 - @PrimaryKeyColumn
应该足够了。
或者您可以更改 table 定义以将 device_id
声明为 UUID
。
我需要在 cassandra 中存储地图列表。那可能吗? 这是我的数据的 json 表示:
{
"deviceId" : "261e92b8-91af-40da-8ba4-c39d821472ec",
"sensors": [
{
"fieldSensorId": "sensorID",
"name": "sensorName",
"location": "sensor location",
"unit": "value units",
"notes": "notes"
},
{
"fieldSensorId": "sensorID 2",
"name": "sensorName 2",
"location": "sensor location 2",
"unit": "value units",
"notes": "notes"
}
]
}
CQL:
CREATE TABLE device_sensors (
device_id text,
sensors list<frozen <map<text,text>>>,
time timeuuid,
PRIMARY KEY (device_id)
)
我仍然无法插入任何数据。在 cassandra 中存储此类数据的正确方法是什么?稍后我需要查询传感器列表 创建传感器 table 并使用 sensor > 引用传感器是否更明智?
我认为问题在于您在 CQL 中将 devide_id
声明为 text
,但是您在源代码中声明了 UUID
,并且 Spring 映射尝试插入数据时将其转换为相应的类型。您可以尝试将 @CassandraType(type = Name.TEXT)
添加到 deviceId
声明中吗?您还可以删除 @Column
声明 - @PrimaryKeyColumn
应该足够了。
或者您可以更改 table 定义以将 device_id
声明为 UUID
。