Cassandra模式设计按时间排序 [英] Cassandra schema design sorted by time

查看:557
本文介绍了Cassandra模式设计按时间排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的cassandra数据建模,我真的需要相同的意见,这里是我的问题:

I'm new on cassandra data modeling, I realy need same advice, here is my problem:

我需要创建一个新的列家庭,将允许我以存储和检索最后插入的分数:

I need to create a new column family that will allow me to store and retrieve last inserted scores :

CREATE TABLE average_score(
    audit_time timestamp PRIMARY KEY,
    pages_count int,
    score float,
)

到主键(我使用随机partinioner(默认)),你有什么解决方案吗?我可以为这个家族列指定一个不同的partitionner吗?

The inserted data is not sorted according to primary key (i'm using a random partinioner(default)), do you have any solution please ? Can I specify a different partitionner just for this family column ?

感谢

推荐答案

系列表,可能为您澄清一些事情:

Here is an example of an hour-partitioned series table that might clarify some things for you:

CREATE TABLE average_score(
    hour timestamp,
    audit_time timeuuid,
    pages_count int,
    score float,
    PRIMARY KEY (hour, audit_time)
)
WITH CLUSTERING ORDER BY (audit_time DESC)




  • 因为它先到,小时是我们的分区键,即它将用于在集群中物理分布我们的数据。 (

    • Because it comes first, hour is our "partition" key, i.e. it will be used to physically distribute our data across the cluster. (When you write, you will have to supply this value, rounded down to the start of the current hour.)

      audit_time 是我们的第一个聚类键,即它用于对特定节点上给定的 hour 分区中的行进行排序和标识。我们选择了 timeuuid 以防止覆盖。 (您可以使用 dateOf 函数拉出实际时间,请参阅 http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/timeuuid_functions_r.html

      audit_time is our first "clustering" key, i.e. it is used to order and identify rows in a given hour partition on a particular node. We've chosen timeuuid to prevent overwrites. (You can pull out the actual time with the dateOf function. See http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/timeuuid_functions_r.html)

      WITH CLUSTERING ORDER BY(audit_time DESC)指示C *在磁盘上以降序存储分区中的行,这可能是正确的决定如果您打算在大多数查询中使用 ORDER BY audit_time DESC 。 (请参见 http://www.datastax.com/documentation/cql /3.1/cql/cql_reference/refClstrOrdr.html

      WITH CLUSTERING ORDER BY (audit_time DESC) directs C* to store rows within a partition in descending order on disk, which is probably the right decision if you intend on using ORDER BY audit_time DESC in most of your queries. (See http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/refClstrOrdr.html)

      注意:虽然我们已将

      干杯!

      PS如果你仍然坚持,DataStax CQL文档是一个伟大的资源,用于数据建模帮助。

      P.S. If you're still stuck, the DataStax CQL documentation is a great resource for data modeling help.

      这篇关于Cassandra模式设计按时间排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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