获取列位置 [英] get column position

查看:125
本文介绍了获取列位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CassandraDB中,使用有序列系列。我知道你可以得到切片,但你能得到的位置。例如,在这个数据模型中,我保存分数如下:

 Scores:
{
1000:bob,lucas,
900:tim
800:mario
}



这是可能的,知道用户的得分为900,他的昵称是tim,知道他在有序列的位置2家庭?

解决方案

Cassandra不提供这种功能,但你可以使用三个独立的CF来实现。考虑这种情况:

 Scores:
{
1000:bob,lucas
900:tim
800:mario
}

PlayerScores:
{
bob :1000
lucas:1000
tim:900
mario:800
}
$ b bScoreTotals:
{
1000:
{
1000:2
}
900:
{
900:1
}
800:
{
800:1
}
}

ScoreTotals CF将与计数器列一起使用,以在用户每次达到该分数时递增/递减值。如果您的分数有更多的粒度(例如910 vs甚至900),您可以将键视为具有列名称作为特定分数的桶。 PlayerScores明显存在,因此您可以查询玩家的分数。



然后,您可以通过简单地将所有分数的总和大于玩家的分数的总和来确定排名。由于分数存储在列名称中,因此您可以使用标准切片查询来获取范围,而无需使用保留顺序的分区器(这会产生一些负面影响)。


In CassandraDB, using an ordered column family. I know you can get slices, but can you get the position. For example, in this datamodel I save scores like this:

"Scores":
{
   "1000": "bob, lucas",
   "900": "tim"
   "800": "mario"
}

Is it possible, knowing that the user has a score of "900" and his nick is "tim", to know that he is at position 2 of the ordered column family?

解决方案

Cassandra does not provide this functionality out of the box, but you could implement this yourself using three separate CFs. Consider this scenario:

"Scores":
{
   "1000": "bob, lucas"
   "900": "tim"
   "800": "mario"
}

"PlayerScores":
{
   "bob": "1000"
   "lucas": "1000"
   "tim": "900"
   "mario": "800"
}

"ScoreTotals":
{
   "1000": 
   {
      "1000":2
   }
   "900": 
   {
      "900":1
   }
   "800": 
   {
      "800":1
   }
}

The ScoreTotals CF would be used with counter columns to increment/decrement the value each time a user achieves that score. If you have additional granularity in your scores (like 910 vs an even 900) you can consider the keys as buckets with column names as specific scores. PlayerScores obviously exists so you can query a score for a player.

You can then determine ranking by simply summing the totals of all scores greater than that of the player. Since scores are stored in column names, you can use a standard slice query to get your range without needing to use an order-preserving partitioner (which has some negative side effects).

这篇关于获取列位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆