CQL SELECT greater-than query on indexed non-key column

前端 未结 3 815
时光说笑
时光说笑 2021-01-12 05:40

EDIT1: added a case to describe the problem after the original question.

I wish to query on a column which is not part of my key. If I understand correctly, I need t

3条回答
  •  醉话见心
    2021-01-12 06:21

    Probably the most flexible way to deal with this scenario in Cassandra will be to have a separate CF for each stat, with sentinel values as keys and the stat value in the column name, like this:

    CF: StatName {
      Key: SomeSentinelValue {
        [Value]:[UserID] = ""
      }
    }
    

    So let's say your stat is NumAnswers and your user IDs are strings:

    CF: NumAnswers {
      Key: 0 {
        150:Joe = ""
        200:Bob = ""
        500:Sue = ""
      }
      Key: 1000 {
        1020:George = ""
        1300:Ringo = ""
        1300:Mary = ""
      }
    }
    

    So you can see that your keys are essentially buckets of values, which can be as coarse or fine grain as needed for your data, and your columns are composites of value + user ID. You can now hand Cassandra a known key (or set of keys) for the coarse range you need (the equality), then do a range query on the first component of the column name. Note that you cannot write the user ID as value, because this would prevent two users from having the same count.

提交回复
热议问题