You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Ben Boule <Be...@rapid7.com> on 2013/06/19 14:47:05 UTC

token() function in CQL3 (1.2.5)

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.

Ben
This electronic message contains information which may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify us by e-mail at (postmaster@rapid7.com) immediately.

Re: token() function in CQL3 (1.2.5)

Posted by Oleksandr Petrov <ol...@gmail.com>.
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 <ty...@datastax.com> wrote:

>
> On Wed, Jun 19, 2013 at 7:47 AM, Ben Boule <Be...@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

Re: token() function in CQL3 (1.2.5)

Posted by Tyler Hobbs <ty...@datastax.com>.
On Wed, Jun 19, 2013 at 7:47 AM, Ben Boule <Be...@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/>