需要 Cassandra 架构
你好 刚开始研究Cassandra,有点困惑。 您能否建议以下架构:
架构:email, city, items1[], items2[]
输入:cityId, item1, item2
我需要:
select email
where city=cityId
and item1 is NOT in items1[]
and item2 is NOT in items2[]
可以吗?
HI
Just started to investifate Cassandra and have a bit confusion.
Could you suggest schema for following:
Schema: email, city, items1[], items2[]
Input: cityId, item1, item2
I need:
select email
where city=cityId
and item1 is NOT in items1[]
and item2 is NOT in items2[]
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要提供更多细节才能获得此问题的彻底答案。
在 Cassandra 0.7 及以上版本中,您可以使用二级索引根据列值选择行(即选择 city=cityId 的行)。您需要通过在列元数据中设置“index_type: KEYS”来在 Cassandra 架构中启用此功能。
请参阅http://www.datastax.com/dev/博客/whats-new-cassandra-07-secondary-indexes 了解更多详细信息。
Cassandra 不提供否定,因此您的“NOT in items1[]”条件可能需要由客户端而不是 Cassandra 节点进行测试。您的 items1 和 items2 有多少个可能的值(只是少数,还是数千?)。
您可能需要纯粹为了回答这种特定类型的查询而设置一个列族,即具有某种基于 item1 和 item2 的复合键的查找表。然而,如果 item1 和 item2 有很多潜在值,那么维护服务器端可能会很困难,并且检索客户端的成本很高!
You may need to give a bit more detail to get a thorough answer to this one.
In Cassandra 0.7 onwards, you can use a secondary index to select rows according to column value (i.e. select rows where city=cityId). You will need to enable this in your Cassandra schema by setting "index_type: KEYS" in the column metadata.
See http://www.datastax.com/dev/blog/whats-new-cassandra-07-secondary-indexes for more details.
Cassandra does not provide negation, so your "NOT in items1[]" conditions may need to be tested by the client, not by the Cassandra nodes. How many possible values are there for your items1 and items2 (just a handful, or thousands?).
You will probably need to set up a column family purely for answering this specific type of query, i.e. a lookup table with some kind of compound key based on item1 and item2. However, this may be challenging to maintain server-side if there are many potential values of item1 and item2, and expensive to retrieve client-side!