Search in sources :

Example 6 with ScanResult

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

the class TestProxyReadWrite method asynchReadWrite.

@Test
public void asynchReadWrite() throws Exception {
    int maxInserts = 10000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    String writer = tpc.proxy().createWriter(userpass, testtable, null);
    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().update(writer, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().flush(writer);
    tpc.proxy().closeWriter(writer);
    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;
    int numRead = 0;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        for (KeyValue kv : kvList.getResults()) {
            assertEquals(i, Integer.parseInt(new String(kv.getKey().getRow())));
            numRead++;
            i += 2;
        }
        hasNext = kvList.isMore();
    }
    assertEquals(maxInserts / 2, numRead);
}
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 ScanResult

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

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

the class SimpleProxyBase method bulkImport.

@Test
public void bulkImport() throws Exception {
    MiniAccumuloClusterImpl cluster = SharedMiniClusterBase.getCluster();
    FileSystem fs = cluster.getFileSystem();
    Path base = cluster.getTemporaryPath();
    Path dir = new Path(base, "test");
    assertTrue(fs.mkdirs(dir));
    // Write an RFile
    String filename = dir + "/bulk/import/rfile.rf";
    FileSKVWriter writer = FileOperations.getInstance().newWriterBuilder().forFile(filename, fs, fs.getConf()).withTableConfiguration(DefaultConfiguration.getInstance()).build();
    writer.startDefaultLocalityGroup();
    writer.append(new org.apache.accumulo.core.data.Key(new Text("a"), new Text("b"), new Text("c")), new Value("value".getBytes(UTF_8)));
    writer.close();
    // Create failures directory
    fs.mkdirs(new Path(dir + "/bulk/fail"));
    // Run the bulk import
    client.importDirectory(creds, tableName, dir + "/bulk/import", dir + "/bulk/fail", true);
    // Make sure we find the data
    String scanner = client.createScanner(creds, tableName, null);
    ScanResult more = client.nextK(scanner, 100);
    client.closeScanner(scanner);
    assertEquals(1, more.results.size());
    ByteBuffer maxRow = client.getMaxRow(creds, tableName, null, null, false, null, false);
    assertEquals(s2bb("a"), maxRow);
}
Also used : Path(org.apache.hadoop.fs.Path) ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) FileSKVWriter(org.apache.accumulo.core.file.FileSKVWriter) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) FileSystem(org.apache.hadoop.fs.FileSystem) Value(org.apache.accumulo.core.data.Value) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) Test(org.junit.Test)

Example 9 with ScanResult

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

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

the class SimpleProxyBase method testDelete.

@Test
public void testDelete() throws Exception {
    client.updateAndFlush(creds, tableName, mutation("row0", "cf", "cq", "value"));
    assertScan(new String[][] { { "row0", "cf", "cq", "value" } }, tableName);
    ColumnUpdate upd = new ColumnUpdate(s2bb("cf"), s2bb("cq"));
    upd.setDeleteCell(false);
    Map<ByteBuffer, List<ColumnUpdate>> notDelete = Collections.singletonMap(s2bb("row0"), Collections.singletonList(upd));
    client.updateAndFlush(creds, tableName, notDelete);
    String scanner = client.createScanner(creds, tableName, null);
    ScanResult entries = client.nextK(scanner, 10);
    client.closeScanner(scanner);
    assertFalse(entries.more);
    assertEquals("Results: " + entries.results, 1, entries.results.size());
    upd = new ColumnUpdate(s2bb("cf"), s2bb("cq"));
    upd.setDeleteCell(true);
    Map<ByteBuffer, List<ColumnUpdate>> delete = Collections.singletonMap(s2bb("row0"), Collections.singletonList(upd));
    client.updateAndFlush(creds, tableName, delete);
    assertScan(new String[][] {}, tableName);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) ArrayList(java.util.ArrayList) List(java.util.List) ByteBuffer(java.nio.ByteBuffer) 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