我如何从 cassandra 超级列访问最近 10 个值
我如何从 cassandra 访问最近 10 个值。我需要从特定的超级列获取最新值。我得到了结果,但未正确排序。我需要按降序对结果进行排序(根据列名/时间戳从最新的开始)
How can i access recent 10 values from cassandra. i need to get the recent values from a particular super column. I am getting the result, but which is not sorted properly. i need to sort the result with descending order(latest first based on the column name/timestamp)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不知道精确的应用程序的情况下,很难对您的需求给出明确的答案,但总的来说,如果我理解正确的话,那么由于 SuperColumn 没有时间戳数据,我相信您需要为每个 SuperColumn 键入一个时间戳或其他数字键,然后在存储配置 XML 中定义一个
CompareWith="LongType"
(或类似的,请检查文档)。这将导致范围内的每个 SuperColumn 都按升序键排序。要检索最新的,您需要将 SliceRange 上的反向属性设置为 true(具体如何完成取决于您使用的语言/库)。请参阅 http://wiki.apache.org/cassandra/API#SliceRange
希望如此将是正确方向的一个点:)。
詹姆斯
Without knowing the precise application it's quite hard to give a definite answer for your needs, but in general and if I understand you correctly then as a SuperColumn has no timestamp data, I believe you would need to key each of your SuperColumns with perhaps a timestamp or other numerical key, and then define a
CompareWith="LongType"
(or similar, check documentation) in the storage config XML.This would result in each of your SuperColumns within the scope being sorted by ascending key. To retrieve the most recent, then, you would need to set the reversed attribute on your SliceRange to true (how exactly this is done will depend on the language/library you're using). See http://wiki.apache.org/cassandra/API#SliceRange
Hopefully this will be a point in the right direction :).
James