Search in sources :

Example 6 with ColumnUpdate

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

Example 7 with ColumnUpdate

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

the class TestProxyReadWrite method addMutation.

private static void addMutation(Map<ByteBuffer, List<ColumnUpdate>> mutations, String row, String cf, String cq, String vis, String value) {
    ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(cf.getBytes()), ByteBuffer.wrap(cq.getBytes()));
    update.setValue(value.getBytes());
    update.setColVisibility(vis.getBytes());
    mutations.put(ByteBuffer.wrap(row.getBytes()), Collections.singletonList(update));
}
Also used : ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate)

Example 8 with ColumnUpdate

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

the class TestProxyClient method main.

public static void main(String[] args) throws Exception {
    TestProxyClient tpc = new TestProxyClient("localhost", 42424);
    String principal = "root";
    Map<String, String> props = new TreeMap<>();
    props.put("password", "secret");
    System.out.println("Logging in");
    ByteBuffer login = tpc.proxy.login(principal, props);
    System.out.println("Creating user: ");
    if (!tpc.proxy().listLocalUsers(login).contains("testuser")) {
        tpc.proxy().createLocalUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes(UTF_8)));
    }
    System.out.println("UserList: " + tpc.proxy().listLocalUsers(login));
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Deleting: ");
    String testTable = "testtableOMGOMGOMG";
    System.out.println("Creating: ");
    if (tpc.proxy().tableExists(login, testTable))
        tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Writing: ");
    Date start = new Date();
    Date then = new Date();
    int maxInserts = 1000000;
    String format = "%1$05d";
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        if (i % 1000 == 0) {
            tpc.proxy().updateAndFlush(login, testTable, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().updateAndFlush(login, testTable, mutations);
    Date end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    // Thread.sleep(1000);
    System.out.println("Writing async: ");
    start = new Date();
    then = new Date();
    mutations.clear();
    String writer = tpc.proxy().createWriter(login, testTable, null);
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        Key pkey = new Key();
        pkey.setRow(result.getBytes(UTF_8));
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        tpc.proxy().update(writer, mutations);
        mutations.clear();
    }
    end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    start = end;
    System.out.println("Closing...");
    tpc.proxy().closeWriter(writer);
    end = new Date();
    System.out.println(" End of closing: " + (end.getTime() - start.getTime()));
    System.out.println("Reading: ");
    String regex = "cf1.*";
    IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
    RegExFilter.setRegexs(is, null, regex, null, null, false);
    String cookie = tpc.proxy().createScanner(login, testTable, null);
    int i = 0;
    start = new Date();
    then = new Date();
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        Date now = new Date();
        System.out.println(i + " " + (now.getTime() - then.getTime()));
        then = now;
        i += kvList.getResultsSize();
        // for (TKeyValue kv:kvList.getResults()) System.out.println(new Key(kv.getKey()));
        hasNext = kvList.isMore();
    }
    end = new Date();
    System.out.println("Total entries: " + i + " total time " + (end.getTime() - start.getTime()));
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) List(java.util.List) Key(org.apache.accumulo.proxy.thrift.Key)

Aggregations

ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)8 ByteBuffer (java.nio.ByteBuffer)4 List (java.util.List)4 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)2 Key (org.apache.accumulo.proxy.thrift.Key)2 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)2 WriterOptions (org.apache.accumulo.proxy.thrift.WriterOptions)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Properties (java.util.Properties)1 ClusterUser (org.apache.accumulo.cluster.ClusterUser)1 Connector (org.apache.accumulo.core.client.Connector)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 Value (org.apache.accumulo.core.data.Value)1