Search in sources :

Example 16 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyReadWrite method readWriteOneShotWithFilterIterator.

/**
 * Insert 100000 cells which have as the row [0..99999] (padded with zeros). Filter the results so only the even numbers come back.
 */
@Test
public void readWriteOneShotWithFilterIterator() throws Exception {
    int maxInserts = 10000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    String regex = ".*[02468]";
    org.apache.accumulo.core.client.IteratorSetting is = new org.apache.accumulo.core.client.IteratorSetting(50, regex, RegExFilter.class);
    RegExFilter.setRegexs(is, regex, null, null, null, false);
    IteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
    ScanOptions opts = new ScanOptions();
    opts.iterators = Collections.singletonList(pis);
    String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        for (KeyValue kv : kvList.getResults()) {
            assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
            i += 2;
        }
        hasNext = kvList.isMore();
    }
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) Test(org.junit.Test)

Aggregations

ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)16 ByteBuffer (java.nio.ByteBuffer)13 HashMap (java.util.HashMap)12 List (java.util.List)12 Test (org.junit.Test)11 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)10 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)8 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)8 Key (org.apache.accumulo.proxy.thrift.Key)5 ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)3 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)3 Range (org.apache.accumulo.proxy.thrift.Range)3 ScanColumn (org.apache.accumulo.proxy.thrift.ScanColumn)3 Value (org.apache.accumulo.core.data.Value)2 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1