Search in sources :

Example 6 with ScanOptions

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

the class TestProxyReadWrite method readWriteBatchOneShotWithFilterIterator.

/**
 * 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 readWriteBatchOneShotWithFilterIterator() 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)

Example 7 with ScanOptions

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

the class SimpleProxyBase method countFiles.

// scan metadata for file entries for the given table
private int countFiles(String table) throws Exception {
    Map<String, String> tableIdMap = client.tableIdMap(creds);
    String tableId = tableIdMap.get(table);
    Key start = new Key();
    start.row = s2bb(tableId + ";");
    Key end = new Key();
    end.row = s2bb(tableId + "<");
    end = client.getFollowing(end, PartialKey.ROW);
    ScanOptions opt = new ScanOptions();
    opt.range = new Range(start, true, end, false);
    opt.columns = Collections.singletonList(new ScanColumn(s2bb("file")));
    String scanner = client.createScanner(creds, MetadataTable.NAME, opt);
    int result = 0;
    while (true) {
        ScanResult more = client.nextK(scanner, 100);
        result += more.getResults().size();
        if (!more.more)
            break;
    }
    return result;
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) Range(org.apache.accumulo.proxy.thrift.Range) PartialKey(org.apache.accumulo.proxy.thrift.PartialKey) Key(org.apache.accumulo.proxy.thrift.Key) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint)

Example 8 with ScanOptions

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

the class TestProxyReadWrite method readWriteOneShotWithRange.

@Test
public void readWriteOneShotWithRange() throws Exception {
    int maxInserts = 100000;
    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();
        }
    }
    Key stop = new Key();
    stop.setRow("5".getBytes());
    ScanOptions opts = new ScanOptions();
    opts.range = new Range(null, false, stop, false);
    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);
        i += kvList.getResultsSize();
        hasNext = kvList.isMore();
    }
    assertEquals(i, 50000);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) Range(org.apache.accumulo.proxy.thrift.Range) ByteBuffer(java.nio.ByteBuffer) Key(org.apache.accumulo.proxy.thrift.Key) Test(org.junit.Test)

Example 9 with ScanOptions

use of org.apache.accumulo.proxy.thrift.ScanOptions 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

ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)9 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)8 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)8 ByteBuffer (java.nio.ByteBuffer)7 List (java.util.List)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)5 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)4 Key (org.apache.accumulo.proxy.thrift.Key)3 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)3 Range (org.apache.accumulo.proxy.thrift.Range)2 WriterOptions (org.apache.accumulo.proxy.thrift.WriterOptions)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterUser (org.apache.accumulo.cluster.ClusterUser)1 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)1 VersioningIterator (org.apache.accumulo.core.iterators.user.VersioningIterator)1 UGIAssumingTransport (org.apache.accumulo.core.rpc.UGIAssumingTransport)1 MiniAccumuloClusterImpl (org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl)1