用于分页的Cassandra CQL令牌功能 [英] Cassandra CQL token function for pagination

查看:75
本文介绍了用于分页的Cassandra CQL令牌功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CQL的新手,并尝试为在cassandra中定义的表添加分页支持,如下所示-

I am new to CQL and trying to add pagination support for my tables defined in cassandra as shown below -

cqlsh:dev> create table emp4 (empid uuid , year varchar , month varchar , day varchar, primary key((year, month, day), empid));
cqlsh:dev> insert into emp4 (empid, year, month, day) values (08f823ac-4dd2-11e5-8ad6-0c4de9ac7563,'2014','03','19');
cqlsh:dev> insert into emp4 (empid, year, month, day) values (08f823ac-4dd2-11e5-8ad6-0c4de9ac7562,'2016','03','19');

cqlsh:dev> select * from emp4;

 year | month | day | empid
------+-------+-----+--------------------------------------
 2016 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
 2015 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac756f
 2014 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7563

When I try to execute a query to fetch the records based on the the following comparison, the statement seems to be incomplete as show below - 

cqlsh:dev> select * from emp4 where token(year, month, day, empid) > token('2014','04',28',08f823ac-4dd2-11e5-8ad6-0c4de9ac7563) LIMIT 1;
       ... ;
       ... 

我正在尝试获取年,月,日更大的记录而不是特定的值和给定的uuid。我认为我以错误的方式执行查询。有人可以帮我吗?

I am trying to fetch records which have year,month, day greater than a specific value and also a given uuid. I think I am executing the query in the wrong way. Can someone help me with this ?

推荐答案

首先,输入发送到令牌的输入( )函数必须匹配您的 partition 键... 不是您的完整主键:

First of all, inputs that you send to the token() function must match your partition key...not your complete primary key:

第二,分区值的顺序不一定与为其生成的标记相同。看看当我再插入三行并使用令牌函数进行查询时会发生什么:

Secondly, the order of your partition values is not necessarily the same as the tokens generated for them. Look what happens when I insert three more rows, and the query using the token function:

 system.token(year, month, day) | year | month | day | empid
--------------------------------+------+-------+-----+--------------------------------------
           -8209483605981607433 | 2016 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
           -6378102587642519893 | 2015 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
           -5253110411337677325 | 2013 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
           -3665221797724106443 | 2011 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
           -2421035798234525153 | 2012 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
            -742508345287024993 | 2014 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7563

(6 rows)

如您所见,这些行按年份确定是 not 。在这种情况下,您的2014行生成了 largest 令牌。因此,查询令牌值大于该年的行将不会产生任何结果。但是,如果我要查询令牌年份大于2013的行,则可以正常工作:

As you can see, the rows are decidedly not in order by year. And in this case your 2014 row has generated the largest token. Therefore querying for rows with a token value larger than that year will yield nothing. But, if I want to query for rows with a token year greater than 2013, it works:

SELECT token(year,month,day),year,month,day,empid FROM emp4 
  WHERE token(year,month,day) > token('2013','03','19');

 system.token(year, month, day) | year | month | day | empid
--------------------------------+------+-------+-----+--------------------------------------
           -3665221797724106443 | 2011 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
           -2421035798234525153 | 2012 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7562
            -742508345287024993 | 2014 |    03 |  19 | 08f823ac-4dd2-11e5-8ad6-0c4de9ac7563

(3 rows)

还要注意,您将需要使用现有行的日期来返回对您更有价值的结果。毕竟, token('2014','04','28')生成的令牌实际上可能不大于生成的令牌token('2014','03','19')

Also note that you will need to use dates of your existing rows to return results that are of more value to you. After all, the token generated by token('2014','04','28') may not actually be greater than the token generated by token('2014','03','19').

这篇关于用于分页的Cassandra CQL令牌功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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