Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Accumulo, mail # user - Can Sort Order Be Reversed?


Copy link to this message
-
Re: Can Sort Order Be Reversed?
Adam Fuchs 2012-05-31, 14:40
Nope, we currently only support one sort order. The closest you can come is
by using an encoding the flips the sort order. In this case, you would take
every byte and subtract it from 255 to get your new row, so:

void convert(byte[] row)
{
  for(int i = 0; i < row.length; i++)
    row[i] = (byte)(255 - row[i]);
}

void foo()
{
  byte[] row = "abcd".getBytes();
  // convert to backwards sort
  convert(row);
  Mutation m = new Mutation(row);
  ...
  BatchWriter bw = ...
  bw.add(m);
  ...

  Scanner s = ...
  for(Entry<Key,Value> e:s)
  {
    byte [] row = e.getKey().getRow();
    // convert back
    convert(row);
    System.out.println(new String(row));
  }
}

On Thu, May 31, 2012 at 10:25 AM, David Medinets
<[EMAIL PROTECTED]>wrote:

> I don't know why it has taken me so long to ask this basic question.
> Rows are stored in Accumulo in sorted order - high to low. Is there a
> configuration option to flip the sort? My specific use case has dates
> as the record key and I want to see the oldest records first.
>