You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Praveen Baratam <pr...@gmail.com> on 2012/03/23 21:41:06 UTC

CQL Reversed and Comparator reversed=true

Hello,

I am a bit confused about how to store and retrieve columns in Reversed
order.

Currently I store comments for every blog post in a wide row per post.

I want to store and retrieve comments for each blog post in
reversed/descending order for efficiency as we display comments in
descending order by time. Each comment gets a time based sortable id which
is stored as part of the first component of the composite type.

Below is the create statement for the column family that stores comments
for posts.

create column family Comments
    with comparator = 'CompositeType(UTF8Type(reversed=True), UTF8Type)'
    and key_validation_class = 'UTF8Type'
    and default_validation_class = 'UTF8Type';

and the CQL I use to retrieve is as follows

SELECT FIRST 100 REVERSED 'z'..'0' from Comments where key = 'xyz';

Am I doing the right thing?

Are the comments stored in descending time order in CF and with this CQL
Query am I retrieving the columns in their natural sort order with out any
additional sorting overhead?

Thank you.

Re: CQL Reversed and Comparator reversed=true

Posted by Praveen Baratam <pr...@gmail.com>.
Thank you Aaron!

On Mon, Mar 26, 2012 at 10:44 PM, aaron morton <aa...@thelastpickle.com>wrote:

> create column family Comments
>     with comparator = 'CompositeType(UTF8Type(reversed=True), UTF8Type)'
>     and key_validation_class = 'UTF8Type'
>     and default_validation_class = 'UTF8Type';
>
> Looks ok.
>
> SELECT FIRST 100 REVERSED 'z'..'0' from Comments where key = 'xyz';
>
> try
> SELECT FIRST 100 REVERSED * from Comments where key = 'xyz';
>
> Cheers
>
>
>   -----------------
> Aaron Morton
> Freelance Developer
> @aaronmorton
> http://www.thelastpickle.com
>
> On 24/03/2012, at 9:41 AM, Praveen Baratam wrote:
>
> Hello,
>
> I am a bit confused about how to store and retrieve columns in Reversed
> order.
>
> Currently I store comments for every blog post in a wide row per post.
>
> I want to store and retrieve comments for each blog post in
> reversed/descending order for efficiency as we display comments in
> descending order by time. Each comment gets a time based sortable id which
> is stored as part of the first component of the composite type.
>
> Below is the create statement for the column family that stores comments
> for posts.
>
> create column family Comments
>     with comparator = 'CompositeType(UTF8Type(reversed=True), UTF8Type)'
>     and key_validation_class = 'UTF8Type'
>     and default_validation_class = 'UTF8Type';
>
> and the CQL I use to retrieve is as follows
>
> SELECT FIRST 100 REVERSED 'z'..'0' from Comments where key = 'xyz';
>
> Am I doing the right thing?
>
> Are the comments stored in descending time order in CF and with this CQL
> Query am I retrieving the columns in their natural sort order with out any
> additional sorting overhead?
>
> Thank you.
>
>
>

Re: CQL Reversed and Comparator reversed=true

Posted by aaron morton <aa...@thelastpickle.com>.
> create column family Comments
>     with comparator = 'CompositeType(UTF8Type(reversed=True), UTF8Type)'
>     and key_validation_class = 'UTF8Type'
>     and default_validation_class = 'UTF8Type';
Looks ok. 

> SELECT FIRST 100 REVERSED 'z'..'0' from Comments where key = 'xyz';
try 
SELECT FIRST 100 REVERSED * from Comments where key = 'xyz';

Cheers


-----------------
Aaron Morton
Freelance Developer
@aaronmorton
http://www.thelastpickle.com

On 24/03/2012, at 9:41 AM, Praveen Baratam wrote:

> Hello,
> 
> I am a bit confused about how to store and retrieve columns in Reversed order.
> 
> Currently I store comments for every blog post in a wide row per post.
> 
> I want to store and retrieve comments for each blog post in reversed/descending order for efficiency as we display comments in descending order by time. Each comment gets a time based sortable id which is stored as part of the first component of the composite type.
> 
> Below is the create statement for the column family that stores comments for posts.
> 
> create column family Comments
>     with comparator = 'CompositeType(UTF8Type(reversed=True), UTF8Type)'
>     and key_validation_class = 'UTF8Type'
>     and default_validation_class = 'UTF8Type';
> 
> and the CQL I use to retrieve is as follows
> 
> SELECT FIRST 100 REVERSED 'z'..'0' from Comments where key = 'xyz';
> 
> Am I doing the right thing?
> 
> Are the comments stored in descending time order in CF and with this CQL Query am I retrieving the columns in their natural sort order with out any additional sorting overhead?
> 
> Thank you.