accumulo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yamini Joshi <yamini.1...@gmail.com>
Subject Modify Keys within iterator
Date Fri, 30 Sep 2016 17:25:56 GMT
Hello Everyone!

I am trying to write an iterator to modify keys within a table (at scan).
My use case is to select a few records that match a certain criterion and
then modify them within the iterator(using the following class) for some
other succeeding iterator/combiner. The problem is that this iterator does
return any records/keys. I added some primitive prints and found that the
keys (this.key) is changed but the output of iterator is nothing. I'd
appreciate if someone could give me any insight. I'm sure I'm making a
teeny tiny mistake somewhere.

Schema:
         row                   colF
colQ                 ts                Val
I/P:    r_1                   f                             f_1
                         v1
         r_1                   fx                            f_1
                          v1

O/P:  f_1                   r
r_1                                      v1
         f_1                   fx
fx                                        v1



public class KeyModifyIterator implements SortedKeyValueIterator<Key,Value>
{

  private SortedKeyValueIterator<Key,Value> source;
  private Key key;
  private Value value;

  @Override
  public void init(SortedKeyValueIterator<Key,Value> source,
Map<String,String> options, IteratorEnvironment env) throws IOException {
    this.source = source;
  }

  @Override
  public boolean hasTop() {
    return key != null;
  }

  @Override
  public void next() throws IOException {
        if (source.hasTop()) {
            ByteSequence currentRow = source.getTopKey().getRowData();
            ByteSequence currentColf =
source.getTopKey().getColumnFamilyData();
            ByteSequence currentColq =
source.getTopKey().getColumnQualifierData();
            long ts = source.getTopKey().getTimestamp();
            String v = source.getTopValue().toString();
            System.out.println("Key = " + currentRow.toString() + " Cf = "
+ currentColf.toString() + " Cq = " + currentColq.toString()  + " val = " +
v.toString());

            if (currentColf.toString().equals("fx")){
                System.out.println("Updating fx" );
                this.key = new Key(currentColq.toArray(),
currentColf.toArray(), currentColf.toArray(), new byte[0], ts);
                this.value = new Value (v.getBytes(UTF_8));
            }
            else{
                System.out.println("Updating other" );
                this.key = new Key(currentColq.toArray(),
"r".getBytes(UTF_8), currentRow.toArray(), new byte[0], ts);
                this.value = new Value (v.getBytes(UTF_8));
                System.out.println(this.key.toString());
            }



            source.next();


          } else {
            this.key = null;
            this.value = null;
      }
  }

  @Override
  public void seek(Range range, Collection<ByteSequence> columnFamilies,
boolean inclusive) throws IOException {
    source.seek(range, columnFamilies, inclusive);
    next();
  }

  @Override
  public Key getTopKey() {
    return key;
  }

  @Override
  public Value getTopValue() {
    return value;
  }

  @Override
  public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment
env) {
    return null;
  }


}


Best regards,
Yamini Joshi

Mime
View raw message