gpt4 book ai didi

json - Cassandra CQL3 : JSON or UDT

转载 作者:行者123 更新时间:2023-12-02 19:59:57 25 4
gpt4 key购买 nike

我需要根据 IP 地址存储有关用户位置的记录,但我不确定如何最好地对其进行建模。

对于每个地址,我们需要记录机器的详细信息(ipaddress、agentId)和机器的位置(isocode、城市)。此信息永远不会更新 - 只会插入和读取。

对此数据的查询将需要提取给定时间段内特定用户的位置信息。

传统上,我会使用带有 JSON blob 的宽行 CF 对此进行建模,如下所示:

CREATE TABLE user_location (
userid text,
timestamp timeuuid,
data text, -- json blob {agentid, isocode, city, ipaddress}
PRIMARY KEY (userid, timestamp)
);

我现在质疑这是否是最好的方法,以及我是否应该用用户定义的类型 (UDT) 替换 JSON,例如:

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)
);

对这种类型的数据进行建模的推荐方法是什么?

最佳答案

我会选择单独的列,除非你真的总是会拉出完整的 Blob 。即使那样,我可能仍然会选择单独的专栏。我看到的 UDT 的最佳用例是能够将它们放入集合中,这样您就可以拥有一个每个项目包含多个字段的集合。

关于json - Cassandra CQL3 : JSON or UDT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23560697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com