You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by "cbertu81@libero.it" <cb...@libero.it> on 2011/02/18 22:16:40 UTC

Are row-keys sorted by the compareWith?

Hi all,
I created a CF in which i need to get, sorted by time, the Rows inside. Each 
Row represents a comment.

<ColumnFamily name="Comments" compareWith="TimeUUIDType" / >

I've created a few rows using as Row Key a generated TimeUUID but when I call 
the Pelops method "GetColumnsFromRows" I don't get the data back as I expect: 
rows are not sorted by TimeUUID.
I though it was probably cause of the random-part of the TimeUUID so I create 
a new CF ...

<ColumnFamily name="Comments2" compareWith="LongType" / >

This time I created a few rows using the java System.CurrentTimeMillis() that 
retrieve a long. I call again the "GetColumnsFromRows" and again the same 
results: data are not sorted!
I've read many times that Rows are sorted as specified in the compareWith but 
I can't see it. 
To solve this problem for the moment I've used a SuperColumnFamily with an 
UNIQUE ROW ... but I think this is just a workaround and not the solution.

<ColumnFamily name="Comments" type="Super" compareWith="TimeUUIDType"  
CompareSubcolumnsWith="BytesType"/ >

Now when I call the "GetSuperColumnsFromRow" I get all the SuperColumns as I 
expected: sorted by TimeUUID. Why it does not happen the same with the Rows? 
I'm confused.

TIA for any help.

Best Regards

Carlo

Re: Are row-keys sorted by the compareWith?

Posted by Dan Washusen <da...@reactive.org>.
Hi Carlo,
As Jonathan mentions the compareWith on a column family def. is defines the order for the columns *within* a row... In order to control the ordering of rows you'll need to use the OrderPreservingPartitioner (http://www.datastax.com/docs/0.7/operations/clustering#tokens-partitioners-ring).


As for getColumnsFromRows; it should be returning you a map of lists. The map is insertion-order-preserving and populated based on the provided list of row keys (so if you iterate over the entries in the map they should be in the same order as the list of row keys). The list for each row entry are definitely in the order that Cassandra provides them, take a look at org.scale7.cassandra.pelops.Selector#toColumnList if you need more info.

Cheers,
Dan

-- 
Dan Washusen
Sent with Sparrow
On Saturday, 19 February 2011 at 8:16 AM, cbertu81@libero.it wrote: 
> Hi all,
> I created a CF in which i need to get, sorted by time, the Rows inside. Each 
> Row represents a comment.
> 
> <ColumnFamily name="Comments" compareWith="TimeUUIDType" / >
> 
> I've created a few rows using as Row Key a generated TimeUUID but when I call 
> the Pelops method "GetColumnsFromRows" I don't get the data back as I expect: 
> rows are not sorted by TimeUUID.
> I though it was probably cause of the random-part of the TimeUUID so I create 
> a new CF ...
> 
> <ColumnFamily name="Comments2" compareWith="LongType" / >
> 
> This time I created a few rows using the java System.CurrentTimeMillis() that 
> retrieve a long. I call again the "GetColumnsFromRows" and again the same 
> results: data are not sorted!
> I've read many times that Rows are sorted as specified in the compareWith but 
> I can't see it. 
> To solve this problem for the moment I've used a SuperColumnFamily with an 
> UNIQUE ROW ... but I think this is just a workaround and not the solution.
> 
> <ColumnFamily name="Comments" type="Super" compareWith="TimeUUIDType" 
> CompareSubcolumnsWith="BytesType"/ >
> 
> Now when I call the "GetSuperColumnsFromRow" I get all the SuperColumns as I 
> expected: sorted by TimeUUID. Why it does not happen the same with the Rows? 
> I'm confused.
> 
> TIA for any help.
> 
> Best Regards
> 
> Carlo
> 

Re: Are row-keys sorted by the compareWith?

Posted by Jonathan Ellis <jb...@gmail.com>.
No.  CompareWith is for columns.

On Fri, Feb 18, 2011 at 3:16 PM, cbertu81@libero.it <cb...@libero.it> wrote:
> Hi all,
> I created a CF in which i need to get, sorted by time, the Rows inside. Each
> Row represents a comment.
>
> <ColumnFamily name="Comments" compareWith="TimeUUIDType" / >
>
> I've created a few rows using as Row Key a generated TimeUUID but when I call
> the Pelops method "GetColumnsFromRows" I don't get the data back as I expect:
> rows are not sorted by TimeUUID.
> I though it was probably cause of the random-part of the TimeUUID so I create
> a new CF ...
>
> <ColumnFamily name="Comments2" compareWith="LongType" / >
>
> This time I created a few rows using the java System.CurrentTimeMillis() that
> retrieve a long. I call again the "GetColumnsFromRows" and again the same
> results: data are not sorted!
> I've read many times that Rows are sorted as specified in the compareWith but
> I can't see it.
> To solve this problem for the moment I've used a SuperColumnFamily with an
> UNIQUE ROW ... but I think this is just a workaround and not the solution.
>
> <ColumnFamily name="Comments" type="Super" compareWith="TimeUUIDType"
> CompareSubcolumnsWith="BytesType"/ >
>
> Now when I call the "GetSuperColumnsFromRow" I get all the SuperColumns as I
> expected: sorted by TimeUUID. Why it does not happen the same with the Rows?
> I'm confused.
>
> TIA for any help.
>
> Best Regards
>
> Carlo
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of DataStax, the source for professional Cassandra support
http://www.datastax.com

Re: Are row-keys sorted by the compareWith?

Posted by Michal Augustýn <au...@gmail.com>.
Hi,

I see "The CompareWith attribute tells Cassandra how to sort the columns for
slicing operations." on wiki (
http://wiki.apache.org/cassandra/StorageConfiguration). So the CompareWith
defines how to sort column (or super-columns) in scope of one row. So this
option is relate to (multi)get_slice operation.

I'm not sure if you can retrieve sorted rows. The only way how to get more
rows is "get_range_slices" method (and "get_indexed_slices") and there is no
sorting.

Augi

2011/2/18 cbertu81@libero.it <cb...@libero.it>

> Hi all,
> I created a CF in which i need to get, sorted by time, the Rows inside.
> Each
> Row represents a comment.
>
> <ColumnFamily name="Comments" compareWith="TimeUUIDType" / >
>
> I've created a few rows using as Row Key a generated TimeUUID but when I
> call
> the Pelops method "GetColumnsFromRows" I don't get the data back as I
> expect:
> rows are not sorted by TimeUUID.
> I though it was probably cause of the random-part of the TimeUUID so I
> create
> a new CF ...
>
> <ColumnFamily name="Comments2" compareWith="LongType" / >
>
> This time I created a few rows using the java System.CurrentTimeMillis()
> that
> retrieve a long. I call again the "GetColumnsFromRows" and again the same
> results: data are not sorted!
> I've read many times that Rows are sorted as specified in the compareWith
> but
> I can't see it.
> To solve this problem for the moment I've used a SuperColumnFamily with an
> UNIQUE ROW ... but I think this is just a workaround and not the solution.
>
> <ColumnFamily name="Comments" type="Super" compareWith="TimeUUIDType"
> CompareSubcolumnsWith="BytesType"/ >
>
> Now when I call the "GetSuperColumnsFromRow" I get all the SuperColumns as
> I
> expected: sorted by TimeUUID. Why it does not happen the same with the
> Rows?
> I'm confused.
>
> TIA for any help.
>
> Best Regards
>
> Carlo
>