【发布时间】:2015-11-24 04:23:01
【问题描述】:
我需要根据 IP 地址存储有关用户位置的记录,但我不确定如何最好地对其进行建模。
对于每个地址,我们需要记录机器的详细信息(ipaddress、agentId)和机器的位置(isocode、city)。此信息永远不会更新 - 只会插入和读取。
对这些数据的查询需要提取特定用户在给定时间段内的位置信息。
传统上,我会使用带有 JSON blob 的宽行 CF 进行建模,如下所示:
CREATE TABLE user_location (
userid text,
timestamp timeuuid,
data text, -- json blob {agentid, isocode, city, ipaddress}
PRIMARY KEY (userid, timestamp)
);
我现在质疑这是否是最好的方法,以及我是否应该将 JSON 替换为用户定义类型 (UDT),例如:
CREATE TYPE machinelocation (
isocode text,
city text,
ipaddress inet
);
CREATE TABLE user_location (
userid text,
timestamp timeuuid,
machinelocations map<text, machinelocation>
PRIMARY KEY (userid, timestamp)
);
或者我应该完全取消 blob 并将 json 分成专用列,ala:
CREATE TABLE user_location (
userid text,
timestamp timeuuid,
agentid text,
isocode text,
city text,
ipaddress text,
PRIMARY KEY (userid, timestamp)
);
对这种类型的数据建模的推荐方法是什么?
【问题讨论】:
标签: json cassandra cql3 user-defined-types