You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Alex Dong <al...@binaryplex.com> on 2010/01/18 00:18:05 UTC

Possible to do sort...limit on Cassandra?

Hi folks,

I'm new to Cassandra.  I'm evaluating Cassandra, HBase and Voldemort  
to see which one matches our app model better. Here is a typical data  
model:

stats {
	word_id: {
		user_id: {
			total_hits: 193,
			monthly_hits: [2, 31, 21, 10, 10, 7, 8, 0, 0, 0, 1, 2]
		},
		..
	}
	...
}

I'm sure that I can pull all the data out from Cassandra and use  
mapreduce to sort or merge.   But I'm wondering are there any way in  
cassandra to 'automate' this process:
1) for a given 'word_id', get a list of user_id: { }  sorted by  
'total_hits'?
2) for two 'word_id's, get an 'intersect' result of the user: {} list  
sorted by the combined 'total_hits'?

Cheers,
Alex

Re: Possible to do sort...limit on Cassandra?

Posted by Jonathan Ellis <jb...@gmail.com>.
that would correspond to the CompareWith I mentioned

On Sun, Jan 17, 2010 at 11:19 PM, Alex Dong <al...@binaryplex.com> wrote:
> Thanks Jonathan,
>
>> two, if you use OrderPreservingPartitioner (whcih lets you specify key
>> sort order)
>
> I guess this is still a rather static approach, right?
> That is, if I use a specified OrderPreservingPartitioner, I will be locked
> into the physical data layout specified here.
> Or, am I missing anything?
>
> According to the BigTable paper, the 'rows' are ordered by PK but you still
> have the flexibility to create index on 'Column' or 'ColumnFamily'.  Do we
> have similar mechanism in Cassandra?
>
> Thanks,
> Alex
>
> On 2010-1-18, at 下午3:28, Jonathan Ellis wrote:
>
>> you get one "sort" for free, which is the column sort you specify with
>> CompareWith
>>
>> two, if you use OrderPreservingPartitioner (whcih lets you specify key
>> sort order)
>>
>> On Sun, Jan 17, 2010 at 5:18 PM, Alex Dong <al...@binaryplex.com>
>> wrote:
>>>
>>> Hi folks,
>>>
>>> I'm new to Cassandra.  I'm evaluating Cassandra, HBase and Voldemort to
>>> see
>>> which one matches our app model better. Here is a typical data model:
>>>
>>> stats {
>>>       word_id: {
>>>               user_id: {
>>>                       total_hits: 193,
>>>                       monthly_hits: [2, 31, 21, 10, 10, 7, 8, 0, 0, 0, 1,
>>> 2]
>>>               },
>>>               ..
>>>       }
>>>       ...
>>> }
>>>
>>> I'm sure that I can pull all the data out from Cassandra and use
>>> mapreduce
>>> to sort or merge.   But I'm wondering are there any way in cassandra to
>>> 'automate' this process:
>>> 1) for a given 'word_id', get a list of user_id: { }  sorted by
>>> 'total_hits'?
>>> 2) for two 'word_id's, get an 'intersect' result of the user: {} list
>>> sorted
>>> by the combined 'total_hits'?
>>>
>>> Cheers,
>>> Alex
>>>
>
> -----------------------------------------------------
> Alex Dong
> Co-Founder BinaryPlex
> http://binaryplex.com/
> twitter: @alexdong
>
>

Re: Possible to do sort...limit on Cassandra?

Posted by Alex Dong <al...@binaryplex.com>.
Thanks Jonathan,

> two, if you use OrderPreservingPartitioner (whcih lets you specify key
> sort order)
I guess this is still a rather static approach, right?
That is, if I use a specified OrderPreservingPartitioner, I will be  
locked into the physical data layout specified here.
Or, am I missing anything?

According to the BigTable paper, the 'rows' are ordered by PK but you  
still have the flexibility to create index on 'Column' or  
'ColumnFamily'.  Do we have similar mechanism in Cassandra?

Thanks,
Alex

On 2010-1-18, at 下午3:28, Jonathan Ellis wrote:

> you get one "sort" for free, which is the column sort you specify with
> CompareWith
>
> two, if you use OrderPreservingPartitioner (whcih lets you specify key
> sort order)
>
> On Sun, Jan 17, 2010 at 5:18 PM, Alex Dong  
> <al...@binaryplex.com> wrote:
>> Hi folks,
>>
>> I'm new to Cassandra.  I'm evaluating Cassandra, HBase and  
>> Voldemort to see
>> which one matches our app model better. Here is a typical data model:
>>
>> stats {
>>        word_id: {
>>                user_id: {
>>                        total_hits: 193,
>>                        monthly_hits: [2, 31, 21, 10, 10, 7, 8, 0,  
>> 0, 0, 1,
>> 2]
>>                },
>>                ..
>>        }
>>        ...
>> }
>>
>> I'm sure that I can pull all the data out from Cassandra and use  
>> mapreduce
>> to sort or merge.   But I'm wondering are there any way in  
>> cassandra to
>> 'automate' this process:
>> 1) for a given 'word_id', get a list of user_id: { }  sorted by
>> 'total_hits'?
>> 2) for two 'word_id's, get an 'intersect' result of the user: {}  
>> list sorted
>> by the combined 'total_hits'?
>>
>> Cheers,
>> Alex
>>

-----------------------------------------------------
Alex Dong
Co-Founder BinaryPlex
http://binaryplex.com/
twitter: @alexdong


Re: Possible to do sort...limit on Cassandra?

Posted by Jonathan Ellis <jb...@gmail.com>.
you get one "sort" for free, which is the column sort you specify with
CompareWith

two, if you use OrderPreservingPartitioner (whcih lets you specify key
sort order)

On Sun, Jan 17, 2010 at 5:18 PM, Alex Dong <al...@binaryplex.com> wrote:
> Hi folks,
>
> I'm new to Cassandra.  I'm evaluating Cassandra, HBase and Voldemort to see
> which one matches our app model better. Here is a typical data model:
>
> stats {
>        word_id: {
>                user_id: {
>                        total_hits: 193,
>                        monthly_hits: [2, 31, 21, 10, 10, 7, 8, 0, 0, 0, 1,
> 2]
>                },
>                ..
>        }
>        ...
> }
>
> I'm sure that I can pull all the data out from Cassandra and use mapreduce
> to sort or merge.   But I'm wondering are there any way in cassandra to
> 'automate' this process:
> 1) for a given 'word_id', get a list of user_id: { }  sorted by
> 'total_hits'?
> 2) for two 'word_id's, get an 'intersect' result of the user: {} list sorted
> by the combined 'total_hits'?
>
> Cheers,
> Alex
>

Re: Possible to do sort...limit on Cassandra?

Posted by JKnight JKnight <be...@gmail.com>.
a) Use combination column name: total_hits and user_id, instead of user_id

b) You can use combination key: word_id1 and word_id2

On Sun, Jan 17, 2010 at 6:18 PM, Alex Dong <al...@binaryplex.com> wrote:

> Hi folks,
>
> I'm new to Cassandra.  I'm evaluating Cassandra, HBase and Voldemort to see
> which one matches our app model better. Here is a typical data model:
>
> stats {
>        word_id: {
>                user_id: {
>                        total_hits: 193,
>                        monthly_hits: [2, 31, 21, 10, 10, 7, 8, 0, 0, 0, 1,
> 2]
>                },
>                ..
>        }
>        ...
> }
>
> I'm sure that I can pull all the data out from Cassandra and use mapreduce
> to sort or merge.   But I'm wondering are there any way in cassandra to
> 'automate' this process:
> 1) for a given 'word_id', get a list of user_id: { }  sorted by
> 'total_hits'?
> 2) for two 'word_id's, get an 'intersect' result of the user: {} list
> sorted by the combined 'total_hits'?
>
> Cheers,
> Alex
>



-- 
Best regards,
JKnight