我知道标题有点宽泛,但我尝试了很多不同错误的东西,所以我打算用这个空间来描述它们中的每一个。我在下面的 datastax 的 python-driver 中有一个模型:
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 和索引查找元素吗?那行得通吗?我超级迷路。