gpt4 book ai didi

python - 如何正确设计这个 cassandra 模型?

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:00 25 4
gpt4 key购买 nike

我知道标题有点宽泛,但我尝试了很多有不同错误的方法,所以我打算用这个空间来描述它们中的每一个。我在下面的 datastax 的 python 驱动程序中有一个模型:

class DIDSummary(Model):
__keyspace__ = 'processor_api'

did = columns.Text(required=True, primary_key=True, partition_key=True)
month = columns.DateTime(required=True, primary_key=True, partition_key=True)
direction = columns.Text(required=True)
duration = columns.Counter(required=True)
cost = columns.Counter(required=True)

但是当我尝试这个时:

didsummaries = DIDSummary.filter(did__in=dids, month__in=datetime_range)

我收到此错误:

code=2200 [Invalid query] message="Partition KEY part did cannot be restricted by IN relation (only the last part of the partition key can)"

然后我尝试了这个:

class DIDSummary(Model):
# ...
month = columns.DateTime(required=True, primary_key=True)
# ...

这引发了错误:

code=2200 [Invalid query] message="Clustering column "month" cannot be restricted by an IN relation"

我也尝试过这个:

class DIDSummary(Model):
# ...
month = columns.DateTime(required=True, primary_key=True, index=True)
# ...

这给了我这个错误:

InvalidRequest: code=2200 [Invalid query] message="Secondary indexes are not supported on counter tables"

当我尝试sync_table(DIDSummary)

最后,我尝试这样做:

class DIDSummary(Model):
# ...
month = columns.DateTime(required=True, primary_key=True)
direction = columns.Text(required=True)
# ...

这甚至不允许我运行服务器,最终在日志中出现此错误:

cassandra.cqlengine.models.ModelDefinitionException: counter models may not have data columns

任何有关我应该如何更好地设计它以便我可以运行上述命令的帮助将不胜感激。谢谢!

编辑:我还必须这样做:

didsummaries = DIDSummary.filter(did__in=dids, month=month)

这意味着实际上did必须是我的partition_key的最后一部分。我可以为每个元素分配一个随机 uuid,然后根据 Primary_keys 和索引查找元素吗?那行得通吗?我 super 迷失。

最佳答案

您还需要将方向作为主键。

来自 Datastax 文档:

Define a counter in a dedicated table only and use the counter data type. You cannot index, delete, or re-add a counter column. All non-counter columns in the table must be defined as part of the primary key.

关于python - 如何正确设计这个 cassandra 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31482215/

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