If I want to have only the queries for:
1. Username, Xp, OtherUserData
2. User with the N-th highest Xp
How would I have to do the data structure and query.
For 1. I would have a structure similar to:
{ Username: { Xp, OtherUserData}}
Would I just have to do a query for 2. over all users, or is there a better option?
I’m not completely sure what you are asking (is Xp the user’s score?), but here’s a guess:
To store user data, create a row per user, keyed on their username (assuming this is unique and fixed) and then a column for each item:
To maintain a high-score table, use a single row (probably in a different column-family), with all users (or those above a certain threshold), with column names that are the scores, and specify a numeric (LongType) Comparator so that the columns are sorted by score:
You can then retrieve the highest N scores by querying for the last or first N columns in this sorted row. You could remove low scores from this row if it gets too big.
Update: As you point out, multiple users could have the same score. A quick-and-dirty solution would be to make the value a list of users:
This is tolerable if you are unlikely to get large number of users with the same score, though awkward since you need to read, update, and write the list.
You could use supercolumns, though these are not usually recommended.
Otherwise you could probably use composite column keys so that you can distinguish users, but maintain columns sorted by score.