You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Christian Decker <de...@gmail.com> on 2010/10/22 13:05:57 UTC

KeyRange over Long keys

Ever since I started implementing my second level caches I've been wondering
on how to deal with this, and thus far I've not found a good solution.

I have a CF acting as a secondary index, and I want to make range queries
against it. Since my keys are Long I simply went ahead and wrote them as
they were, which resulted them in being stored as UTF8 Strings. Now I'm
having the problem that if I want to make a range query on those keys (lets
say 1-100) they will be matched as string against each other, meaning that
55 > 100, which is not what I want.

Is there a simple way to make such queries by just adjusting the key?
Specifically I'm wondering if I could create a byte representation of the
Long that would also be lexicographically ordered.

Anyone had a similar problem?

Regards,
Chris

Re: KeyRange over Long keys

Posted by Stu Hood <st...@rackspace.com>.
> Specifically I'm wondering if I could create a byte representation of the Long
> that would also be lexicographically ordered.
This is probably what you want to do, combined with the ByteOrderedPartitioner in 0.7

-----Original Message-----
From: "Eric Czech" <er...@nextbigsound.com>
Sent: Friday, October 22, 2010 7:05am
To: user@cassandra.apache.org
Subject: Re: KeyRange over Long keys

Prepend zeros to every number out to a fixed length determined by the
maximum possible value.  As an example, 0055 < 0100 in a lexical ordering
where the maximum value is 9999.

On Fri, Oct 22, 2010 at 5:05 AM, Christian Decker <
decker.christian@gmail.com> wrote:

> Ever since I started implementing my second level caches I've been
> wondering on how to deal with this, and thus far I've not found a good
> solution.
>
> I have a CF acting as a secondary index, and I want to make range queries
> against it. Since my keys are Long I simply went ahead and wrote them as
> they were, which resulted them in being stored as UTF8 Strings. Now I'm
> having the problem that if I want to make a range query on those keys (lets
> say 1-100) they will be matched as string against each other, meaning that
> 55 > 100, which is not what I want.
>
> Is there a simple way to make such queries by just adjusting the key?
> Specifically I'm wondering if I could create a byte representation of the
> Long that would also be lexicographically ordered.
>
> Anyone had a similar problem?
>
> Regards,
> Chris
>



Re: KeyRange over Long keys

Posted by Eric Czech <er...@nextbigsound.com>.
Prepend zeros to every number out to a fixed length determined by the
maximum possible value.  As an example, 0055 < 0100 in a lexical ordering
where the maximum value is 9999.

On Fri, Oct 22, 2010 at 5:05 AM, Christian Decker <
decker.christian@gmail.com> wrote:

> Ever since I started implementing my second level caches I've been
> wondering on how to deal with this, and thus far I've not found a good
> solution.
>
> I have a CF acting as a secondary index, and I want to make range queries
> against it. Since my keys are Long I simply went ahead and wrote them as
> they were, which resulted them in being stored as UTF8 Strings. Now I'm
> having the problem that if I want to make a range query on those keys (lets
> say 1-100) they will be matched as string against each other, meaning that
> 55 > 100, which is not what I want.
>
> Is there a simple way to make such queries by just adjusting the key?
> Specifically I'm wondering if I could create a byte representation of the
> Long that would also be lexicographically ordered.
>
> Anyone had a similar problem?
>
> Regards,
> Chris
>