卡桑德拉:柱族与超级柱族

Cha*_*ani 4 database-design cassandra nosql

我有一个要求,我需要我的数据库来存储以下数据:

- For each build, store the results of 3 performance runs. The result includes tps and latency. 
Run Code Online (Sandbox Code Playgroud)

阅读cassandra数据模型,这直接映射到以下格式的超级列族:

BenchmarkSuperColumnFamily= {

build_1: {
   Run1: {1000K, 0.5ms}
   Run2: {1000K, 0.5ms}
   Run3: {1000K, 0.5ms}
}

build_2: {
   Run1: {1000K, 0.5ms}
   Run2: {1000K, 0.5ms}
   Run3: {1000K, 0.5ms}
}
...

}
Run Code Online (Sandbox Code Playgroud)

但是,我在下面的回答中读到,不鼓励使用Super Column系列.我想知道是否有更好的方法为我的要求创建模型.

PS,我从下面的文章中借用了JSONish表示法

nic*_*ley 6

您链接到的StackOverflow答案是正确的.您不应该在新应用程序中使用SuperColumns.但它们是为了向后兼容而存在的.

通常,复合列可用于模拟超级列提供的任何模型.基本上,它们允许您将列名分成多个部分.因此,如果您要指定'CompositeType(UTF8Type,UTF8Type)'的比较器,您的数据模型最终会看起来像这样:

BenchmarkColumnFamily= {

   build_1: {
       (Run1, TPS) : 1000K
       (Run1, Latency) : 0.5ms
       (Run2, TPS) : 1000K
       (Run2, Latency) : 0.5ms
       (Run3, TPS) : 1000K
       (Run3, Latency) : 0.5ms
    }

    build_2: {
       ...
    }
...

}
Run Code Online (Sandbox Code Playgroud)

使用上述模型,您可以使用单个查询为单次运行获取单个数据点,为单次运行获取所有数据点,或为多次运行获取所有数据点.

有关复合柱的更多信息:http: //www.datastax.com/dev/blog/introduction-to-composite-columns-part-1