Nosql 按不工作顺序进行聚类

Nosql 按不工作顺序进行聚类,nosql,cassandra,time-series,modeling,cql,Nosql,Cassandra,Time Series,Modeling,Cql,我刚刚在创建基于时间的有序表时遇到了奇怪的行为。 通常情况下,对于status_by_user表的模式,最新状态应始终位于顶部,当检索插入的数据时,我发现其顺序不正确。(查看cqlsh输出) 我错过了什么 -- Running on Cassandra-2.0.4 -- Inserted some pseudo randomly data from 2013 and 2014 CREATE TABLE status_by_user ( id timeuui

我刚刚在创建基于时间的有序表时遇到了奇怪的行为。 通常情况下,对于status_by_user表的模式,最新状态应始终位于顶部,当检索插入的数据时,我发现其顺序不正确。(查看cqlsh输出)

我错过了什么

    -- Running on Cassandra-2.0.4
    -- Inserted some pseudo randomly data from 2013 and 2014 
    CREATE TABLE status_by_user (
       id timeuuid,
       uname text
       status_ts timestamp,
       status_ts_day int, -- YYYYMMDD
       status_comment text,
      PRIMARY KEY ((uname,status_ts_day),id)
    ) WITH CLUSTERING ORDER BY (id DESC);


    cqlsh> select dateOf(id),status_ts from status_by_user LIMIT 110;

     dateOf(id)                               | status_ts
    ------------------------------------------+------------------------------------------
     2014-03-08 18:46:39Romance Standard Time | 2014-03-08 18:46:39Romance Standard Time
     2014-03-08 18:46:38Romance Standard Time | 2014-03-08 18:46:38Romance Standard Time
     2014-03-08 18:46:38Romance Standard Time | 2014-03-08 18:46:38Romance Standard Time
     2014-03-08 06:46:39Romance Standard Time | 2014-03-08 06:46:39Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
     2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
     2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
     2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
     2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
     2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
     2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
     2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
     2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
     2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
     2014-03-15 17:46:39Romance Standard Time | 2014-03-15 17:46:39Romance Standard Time
     2014-03-15 17:46:39Romance Standard Time | 2014-03-15 17:46:39Romance Standard Time
     2014-03-15 17:46:38Romance Standard Time | 2014-03-15 17:46:38Romance Standard Time
     2014-03-15 17:46:37Romance Standard Time | 2014-03-15 17:46:37Romance Standard Time
     2014-03-15 17:46:37Romance Standard Time | 2014-03-15 17:46:37Romance Standard Time
     2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
     2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
     2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
     2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
     2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
     2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
     2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
     2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
     2013-12-19 01:46:37Romance Standard Time | 2013-12-19 01:46:37Romance Standard Time
     2013-10-24 00:46:39Romance Daylight Time | 2013-10-24 00:46:39Romance Daylight Time
     2013-10-24 00:46:39Romance Daylight Time | 2013-10-24 00:46:39Romance Daylight Time
     2013-10-24 00:46:38Romance Daylight Time | 2013-10-24 00:46:38Romance Daylight Time
     2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
     2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
     2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
 ? ->2013-12-25 01:46:39Romance Standard Time | 2013-12-25 01:46:39Romance Standard Time
     2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
     2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
     2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
     2013-12-25 01:46:37Romance Standard Time | 2013-12-25 01:46:37Romance Standard Time
 ? ->2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
     ..
     ..
    (110 rows)
更新:


我认为主键的分区部分(uname,status_tsu_day)在排序数据时没有考虑到,因为知道排序是由集群键“id”完成的

有人能澄清一下吗

    cqlsh> select uname,status_ts_day,dateOf(id), status_ts from trans.status_by_user LIMIT 110;

     uname  | status_ts_day | dateOf(id)                               | status_ts
    --------+---------------+------------------------------------------+------------------------------------------
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test47 |      20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 11:13:20Romance Standard Time | 2014-01-14 11:13:20Romance Standard Time
     test10 |      20140114 | 2014-01-14 11:13:20Romance Standard Time | 2014-01-14 11:13:20Romance Standard Time
      test2 |      20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
      test2 |      20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
      test2 |      20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
      test2 |      20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
      test2 |      20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
     test66 |      20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
     test66 |      20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
     test66 |      20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
     test66 |      20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
     test66 |      20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
     test34 |      20131223 | 2013-12-23 00:13:20Romance Standard Time | 2013-12-23 00:13:20Romance Standard Time
     test34 |      20131223 | 2013-12-23 00:13:20Romance Standard Time | 2013-12-23 00:13:20Romance Standard Time
     test33 |      20140305 | 2014-03-05 06:13:20Romance Standard Time | 2014-03-05 06:13:20Romance Standard Time
     test33 |      20140305 | 2014-03-05 06:13:20Romance Standard Time | 2014-03-05 06:13:20Romance Standard Time

    (110 rows)

提前感谢您的建议。

您能在select查询中包含uname吗?我敢打赌,如果您这样做,您将看到结果也按用户排序,这是分区键的一部分,但在select语句中被省略。从查询中删除列不会对结果重新排序;引擎仍然按照相同的顺序处理行。我认为主键的分区部分“(uname,status_tsu_________________________________________。有人能澄清一下吗?“给定分区键的行是按照集群列的顺序存储的”,这一措辞可能有点模棱两可。集群只在由唯一分区键值定义的行子集内起作用。在确定行的位置时,可以将其视为一个两步算法:(1)查看分区键值,并使用该键值确定行的位置;(2) 查看集群键值以确定在该节点中放置行的位置。可以看出,分区键始终是决定最终位置的第一个因素;任何进一步的排序只能在分区键建立的限制内完成。