Cassandra Slice 查询 CompositeType 的部分内容
我有一个由四个字段组成的复合列:(field1、field2、field3、field4)。我需要执行以下切片查询: 1. 获取field2具有特定值的所有复合列,其他字段不重要。假设我有一个行键的三个复合列:('ACTIVE', '35', 'Name', 'Time'), ('INACTIVE', '35', 'City', 'Country'), 和(“被动”、“25”、“时间”、“区域”)。假设 field3 的行键和值为“35”,我应该得到前两个复合列的结果。任何建议都将受到高度赞赏。
I have a composite column made of four fields: (field1, field2, field3, field4). I need to perform following slice queries:
1. Get All composite columns where field2 has a specific value and other fields do not matter. Let us say I have three composite columns for a row key: ('ACTIVE', '35', 'Name', 'Time'), ('INACTIVE', '35', 'City', 'Country'), and ('PASSIVE', '25', 'Time', 'Zone'). Given the row key and value of field3 as '35' I should get results with first two composite columns. Any suggestion will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
field1 可以有多少个不同的值?具有复合键的列首先按第一个维度排序,然后是下一个维度,依此类推。要检索 field2=x 的所有值,您至少必须执行 |field1|读取或扫描整行。您是否考虑过交换 field2 和 field1 ?这将使这个查询变得更容易。
如果您需要对 field1=x 的所有值进行查询,并且单独希望对 field2=y 进行查询,您还可以考虑插入数据两次,并对组合键的维度使用不同的顺序。如果您的日期是一次性写入的,则此方法效果最佳。如果这是不可接受的,那么唯一的选择是执行三个查询:
["ACTIVE";y;"";""] -> [“活动”;y;“”;“”]
["INACTIVE";y:"";""] -> [“不活动”;y:“”;“”]
[“被动”;y;“”;“”-> ["PASSIVE";y:"";""]
如果 field1 的可能值超过三个,则此方法不会很好地工作。
How many different values can field1 have? Columns with composite keys are sorted by the first dimension first, then the next and so on. To retrieve all the values with field2=x you have to do at least |field1| reads, or scan the entire row. Have you considered swapping field2 and field1? That would make this query easier.
If you need to do queries for all values with field1=x, and you separately want to do queries with field2=y, you could also consider inserting your data twice, with different ordering for the dimensions of the composite keys. This works best if you date is write-once. If this isn't acceptable, then the only option is to do three queries:
["ACTIVE";y;"";""] -> ["ACTIVE";y;"";""]
["INACTIVE";y:"";""] -> ["INACTIVE";y:"";""]
["PASSIVE";y;"";"" -> ["PASSIVE";y:"";""]
This wouldn't work so well if there were more than three possible values for field1.