cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamar Fraenkel <ta...@tok-media.com>
Subject Re: Long type column names in reverse order
Date Sun, 22 Apr 2012 05:33:27 GMT
Maybe I don't get what you are trying to do, but using Cassandra and
Hector, what I do is:
I have the following column family definition
CREATE COLUMN FAMILY CF_NAME
    with comparator = 'CompositeType(LongType(reversed=true),UUIDType)'
    and default_validation_class = 'UTF8Type'
    and key_validation_class = 'UUIDType';

Then to iterate it I use ColumnSliceIterator. You can also leave out the
"reversed=true" and use ColumnSliceIterator to iterate backwards.



*Tamar Fraenkel *
Senior Software Engineer, TOK Media

[image: Inline image 1]

tamar@tok-media.com
Tel:   +972 2 6409736
Mob:  +972 54 8356490
Fax:   +972 2 5612956





On Fri, Apr 20, 2012 at 10:47 PM, Tarun Gupta <tarun.gupta@technogica.com>wrote:

> Thanks, This post helped a lot, I discovered that the built-in comparators
> have a static instance called *reverseComparator.* My exact requirement
> was to create an API that allows creating a Column family with the required
> parameters, one such parameter was a flag that indicates the column order.
> I am using Hector API for this purpose. The way I finally solved this is as
> follows :
>
> *public class ReverseColumnComparator extends  AbstractType<ByteBuffer> {*
> * *
> * private static Comparator<ByteBuffer> otherInstance =
> BytesType.instance.reverseComparator ;*
> * *
> * public static final ReverseColumnComparator instance = new
> ReverseColumnComparator();*
> * *
> * @Override*
> * public int compare(ByteBuffer o1, ByteBuffer o2) {*
> * return otherInstance.compare(o1, o2);*
> * }*
> * @Override*
> * public ByteBuffer compose(ByteBuffer arg0) {*
> * return BytesType.instance.compose(arg0);*
> * }*
> * @Override*
> * public ByteBuffer decompose(ByteBuffer arg0) {*
> * return BytesType.instance.decompose(arg0);*
> * }*
> * @Override*
> * public String getString(ByteBuffer arg0) {*
> * return BytesType.instance.getString(arg0);*
> * }*
> * @Override*
> * public void validate(ByteBuffer arg0) throws MarshalException {*
> * BytesType.instance.validate(arg0);*
> * }*
> *}*
>
> Regards,
> Tarun
>
>
> On Fri, Apr 20, 2012 at 11:46 PM, Edward Capriolo <edlinuxguru@gmail.com>wrote:
>
>> I think you can drop the compiler since that feature already exists.
>>
>> http://thelastpickle.com/2011/10/03/Reverse-Comparators/
>>
>>
>> On Fri, Apr 20, 2012 at 12:57 PM, Tarun Gupta
>> <tarun.gupta@technogica.com> wrote:
>> > Hi,
>> >
>> > My requirements is to get retrieve column values, sorted by column
>> names in
>> > reverse order (column names are 'long' type). The way I am trying to
>> > implement this is by using a custom comparator. I have written the
>> custom
>> > comparator by using 'org.apache.cassandra.db.marshal.BytesType' and
>> altering
>> > the compare() method. While inserting values it works fine but while
>> > retrieving the values I am getting
>> > "ColumnSerializer$CorruptColumnException".
>> >
>> > I've attached the Comparator class. Please suggest what should I change
>> to
>> > make it work.
>> >
>> > Regards
>> > Tarun
>>
>
>

Mime
View raw message