Search in sources :

Example 91 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestQueryExecute method queryExecuteOperateExp.

@Test
public void queryExecuteOperateExp() {
    String binName = "foo";
    Expression exp = Exp.build(Exp.val("bar"));
    int begin = 3;
    int end = 9;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    ExecuteTask task = client.execute(null, stmt, ExpOperation.write(binName, exp, ExpWriteFlags.DEFAULT));
    task.waitTillComplete(3000, 3000);
    stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            String value = record.getString(binName);
            if (value == null) {
                fail("Bin " + binName + " not found");
            }
            if (!value.equals("bar")) {
                fail("Data mismatch. Expected bar. Received " + value);
            }
            count++;
        }
        assertEquals(end - begin + 1, count);
    } finally {
        rs.close();
    }
}
Also used : Expression(com.aerospike.client.exp.Expression) Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) ExecuteTask(com.aerospike.client.task.ExecuteTask) Test(org.junit.Test)

Example 92 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestListExp method modifyWithContext.

@Test
public void modifyWithContext() {
    List<Value> listSubA = new ArrayList<Value>();
    listSubA.add(Value.get("e"));
    listSubA.add(Value.get("d"));
    listSubA.add(Value.get("c"));
    listSubA.add(Value.get("b"));
    listSubA.add(Value.get("a"));
    List<Value> listA = new ArrayList<Value>();
    listA.add(Value.get("a"));
    listA.add(Value.get("b"));
    listA.add(Value.get("c"));
    listA.add(Value.get("d"));
    listA.add(Value.get(listSubA));
    List<Value> listB = new ArrayList<Value>();
    listB.add(Value.get("x"));
    listB.add(Value.get("y"));
    listB.add(Value.get("z"));
    client.operate(null, keyA, ListOperation.appendItems(ListPolicy.Default, binA, listA), ListOperation.appendItems(ListPolicy.Default, binB, listB), Operation.put(new Bin(binC, "M")));
    CTX ctx = CTX.listIndex(4);
    Record record;
    List<?> result;
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append binB/binC to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.listBin(binB), ListExp.append(ListPolicy.Default, Exp.stringBin(binC), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append local listB and local "M" string to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.val(listB), ListExp.append(ListPolicy.Default, Exp.val("M"), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
}
Also used : Bin(com.aerospike.client.Bin) CTX(com.aerospike.client.cdt.CTX) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 93 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestListExp method expReturnsList.

@Test
public void expReturnsList() {
    List<Value> list = new ArrayList<Value>();
    list.add(Value.get("a"));
    list.add(Value.get("b"));
    list.add(Value.get("c"));
    list.add(Value.get("d"));
    Expression exp = Exp.build(Exp.val(list));
    Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC), ExpOperation.read("var", exp, ExpReadFlags.DEFAULT));
    // System.out.println(record);
    List<?> results = record.getList(binC);
    assertEquals(2, results.size());
    List<?> rlist = (List<?>) results.get(1);
    assertEquals(4, rlist.size());
    List<?> results2 = record.getList("var");
    assertEquals(4, results2.size());
}
Also used : Expression(com.aerospike.client.exp.Expression) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 94 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestOperate method operate.

@Test
public void operate() {
    // Write initial record.
    Key key = new Key(args.namespace, args.set, "opkey");
    Bin bin1 = new Bin("optintbin", 7);
    Bin bin2 = new Bin("optstringbin", "string value");
    client.put(null, key, bin1, bin2);
    // Add integer, write new string and read record.
    Bin bin3 = new Bin(bin1.name, 4);
    Bin bin4 = new Bin(bin2.name, "new string");
    Record record = client.operate(null, key, Operation.add(bin3), Operation.put(bin4), Operation.get());
    assertBinEqual(key, record, bin3.name, 11);
    assertBinEqual(key, record, bin4);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 95 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestOperateHll method operateIntersectHLL.

@Test
public void operateIntersectHLL() {
    String otherBinName = binName + "other";
    for (ArrayList<Integer> desc : legalDescriptions) {
        int indexBits = desc.get(0);
        int minhashBits = desc.get(1);
        if (minhashBits != 0) {
            break;
        }
        Record record = assertSuccess("init", key, Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, entries, indexBits, minhashBits), Operation.get(binName), HLLOperation.add(HLLPolicy.Default, otherBinName, entries, indexBits, 4), Operation.get(otherBinName));
        List<HLLValue> hlls = new ArrayList<HLLValue>();
        List<HLLValue> hmhs = new ArrayList<HLLValue>();
        List<?> resultList = record.getList(binName);
        hlls.add((HLLValue) resultList.get(1));
        hlls.add(hlls.get(0));
        resultList = record.getList(otherBinName);
        hmhs.add((HLLValue) resultList.get(1));
        hmhs.add(hmhs.get(0));
        record = assertSuccess("intersect", key, HLLOperation.getIntersectCount(binName, hlls), HLLOperation.getSimilarity(binName, hlls));
        resultList = record.getList(binName);
        long intersectCount = (Long) resultList.get(0);
        assertTrue("intersect value too high", intersectCount < 1.8 * entries.size());
        hlls.add(hlls.get(0));
        assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.getIntersectCount(binName, hlls));
        assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.getSimilarity(binName, hlls));
        record = assertSuccess("intersect", key, HLLOperation.getIntersectCount(binName, hmhs), HLLOperation.getSimilarity(binName, hmhs));
        resultList = record.getList(binName);
        intersectCount = (Long) resultList.get(0);
        assertTrue("intersect value too high", intersectCount < 1.8 * entries.size());
        hmhs.add(hmhs.get(0));
        assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, HLLOperation.getIntersectCount(binName, hmhs));
        assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, HLLOperation.getSimilarity(binName, hmhs));
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Test(org.junit.Test)

Aggregations

Record (com.aerospike.client.Record)259 Key (com.aerospike.client.Key)140 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)75 Bin (com.aerospike.client.Bin)70 AerospikeException (com.aerospike.client.AerospikeException)62 Value (com.aerospike.client.Value)54 WritePolicy (com.aerospike.client.policy.WritePolicy)47 List (java.util.List)41 HashMap (java.util.HashMap)36 ThrowingRunnable (org.junit.function.ThrowingRunnable)32 BatchPolicy (com.aerospike.client.policy.BatchPolicy)29 Policy (com.aerospike.client.policy.Policy)29 Statement (com.aerospike.client.query.Statement)23 RecordSet (com.aerospike.client.query.RecordSet)22 Expression (com.aerospike.client.exp.Expression)18 Map (java.util.Map)15 HLLValue (com.aerospike.client.Value.HLLValue)14 Collections.singletonList (java.util.Collections.singletonList)9 MapPolicy (com.aerospike.client.cdt.MapPolicy)7