incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleksandr Petrov <oleksandr.pet...@gmail.com>
Subject Re: token() function in CQL3 (1.2.5)
Date Sat, 29 Jun 2013 16:27:46 GMT
Tokens are very useful for pagination and "world" iteration. For example,
when you want to scan an entire table, you want to use token() function.

You can refer two guides we've written for Clojure driver (although they do
not contain much clojure-specific information.
First one is Data Modelling / Static Tables guide:
http://clojurecassandra.info/articles/data_modelling.html#toc_1
and second one would be K/V guide / Pagination:
http://clojurecassandra.info/articles/kv.html#toc_7


On Wed, Jun 19, 2013 at 5:06 PM, Tyler Hobbs <tyler@datastax.com> wrote:

>
> On Wed, Jun 19, 2013 at 7:47 AM, Ben Boule <Ben_Boule@rapid7.com> wrote:
>
>>  Can anyone explain this to me?  I have been looking through the source
>> code but can't seem to find the answer.
>>
>> The documentation mentions using the token() function to change a value
>> into it's token for use in queries.   It always mentions it as taking a
>> single parameter:
>>
>> SELECT * FROM posts WHERE token(userid) > token('tom') AND token(userid) <
token('bob')
>>
>>
>> However on my 1.2.5 node I am getting the following error:
>>
>> e.x.
>>
>> create table foo (
>>     organization text,
>>     type text,
>>     time timestamp,
>>     id uuid,
>>     primary key ((organization, type, time), id))
>>
>> select * from foo where organization = 'companyA' and type = 'typeB' and
>> token(time) < token('somevalue') and token(time) > token('othervalue')
>>
>> Bad Request: Invalid number of arguments in call to function token: 3
>> required but 1 provided
>>
>> What are the other two parameters?  We don't currently use the token
>> function but I was experimenting seeing if I could move the time into the
>> partition key for a table like this to better distribute the rows.  But I
>> can't seem to figure out how to get token() working.
>>
>
> token() acts on the entire partition key, which for you is (organization,
> type, time), hence the 3 required values.
>
> In order to better distribute the rows, I suggest using a time bucket as
> part of the partition key.  For example, you might use only the date
> portion of the timestamp as the time bucket.
>
> These posts talk about doing something similar with the Thrift API, but
> they will probably still be helpful:
> - http://rubyscale.com/2011/basic-time-series-with-cassandra/
> - http://www.datastax.com/dev/blog/advanced-time-series-with-cassandra
>
> --
> Tyler Hobbs
> DataStax <http://datastax.com/>
>



-- 
alex p

Mime
View raw message