Search in sources :

Example 96 with Record

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

the class TestOperateHll method assertAddInit.

public void assertAddInit(int nIndexBits, int nMinhashBits) {
    client.delete(null, key);
    String msg = "Fail - nIdexBits " + nIndexBits + " nMinhashBits " + nMinhashBits;
    HLLPolicy p = HLLPolicy.Default;
    Operation[] ops = new Operation[] { HLLOperation.add(p, binName, entries, nIndexBits, nMinhashBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName), HLLOperation.add(p, binName, entries) };
    if (!checkBits(nIndexBits, nMinhashBits)) {
        assertThrows(msg, key, AerospikeException.class, ResultCode.PARAMETER_ERROR, ops);
        return;
    }
    Record record = assertSuccess(msg, key, ops);
    List<?> resultList = record.getList(binName);
    long count = (Long) resultList.get(1);
    long count1 = (Long) resultList.get(2);
    List<?> description = (List<?>) resultList.get(3);
    long nAdded = (Long) resultList.get(4);
    assertDescription(msg, description, nIndexBits, nMinhashBits);
    assertHLLCount(msg, nIndexBits, count, entries.size());
    assertEquals(count, count1);
    assertEquals(nAdded, 0);
}
Also used : Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Operation(com.aerospike.client.Operation) HLLOperation(com.aerospike.client.operation.HLLOperation) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Example 97 with Record

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

the class TestOperateHll method assertInit.

public void assertInit(int nIndexBits, int nMinhashBits, boolean shouldPass) {
    String msg = "Fail - nIndexBits " + nIndexBits + " nMinhashBits " + nMinhashBits;
    HLLPolicy p = HLLPolicy.Default;
    Operation[] ops = new Operation[] { HLLOperation.init(p, binName, nIndexBits, nMinhashBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName) };
    if (!shouldPass) {
        assertThrows(msg, key, AerospikeException.class, ResultCode.PARAMETER_ERROR, ops);
        return;
    }
    Record record = assertSuccess(msg, key, ops);
    List<?> resultList = record.getList(binName);
    long count = (Long) resultList.get(1);
    long count1 = (Long) resultList.get(2);
    List<?> description = (List<?>) resultList.get(3);
    assertDescription(msg, description, nIndexBits, nMinhashBits);
    assertEquals(0, count);
    assertEquals(0, count1);
}
Also used : Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Operation(com.aerospike.client.Operation) HLLOperation(com.aerospike.client.operation.HLLOperation) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Example 98 with Record

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

the class TestOperateHll method operateEmptySimilarity.

@Test
public void operateEmptySimilarity() {
    for (ArrayList<Integer> desc : legalDescriptions) {
        int nIndexBits = desc.get(0);
        int nMinhashBits = desc.get(1);
        Record record = assertSuccess("init", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName, nIndexBits, nMinhashBits), Operation.get(binName));
        List<?> resultList = record.getList(binName);
        List<HLLValue> hlls = new ArrayList<HLLValue>();
        hlls.add((HLLValue) resultList.get(1));
        record = assertSuccess("test", key, HLLOperation.getSimilarity(binName, hlls), HLLOperation.getIntersectCount(binName, hlls));
        resultList = record.getList(binName);
        double sim = (Double) resultList.get(0);
        long intersectCount = (Long) resultList.get(1);
        String msg = "(" + nIndexBits + ", " + nMinhashBits + ")";
        assertEquals(msg, 0, intersectCount);
        assertEquals(msg, Double.NaN, sim, 0.0);
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 99 with Record

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

the class TestExpOperation method expMerge.

@Test
public void expMerge() {
    Expression e = Exp.build(Exp.eq(Exp.intBin(binA), Exp.val(0)));
    Expression eand = Exp.build(Exp.and(Exp.expr(e), Exp.eq(Exp.intBin(binD), Exp.val(2))));
    Expression eor = Exp.build(Exp.or(Exp.expr(e), Exp.eq(Exp.intBin(binD), Exp.val(2))));
    Record record = client.operate(null, keyA, ExpOperation.read("res1", eand, ExpReadFlags.DEFAULT), ExpOperation.read("res2", eor, ExpReadFlags.DEFAULT));
    assertRecordFound(keyA, record);
    boolean res1 = record.getBoolean("res1");
    assertFalse(res1);
    boolean res2 = record.getBoolean("res2");
    assertTrue(res2);
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 100 with Record

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

the class TestExpOperation method expReturnsBoolean.

@Test
public void expReturnsBoolean() {
    Expression exp = Exp.build(Exp.eq(Exp.intBin(binA), Exp.val(1)));
    Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC), ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
    assertRecordFound(keyA, record);
    // System.out.println(record);
    List<?> results = record.getList(binC);
    boolean val = (Boolean) results.get(1);
    assertTrue(val);
    val = record.getBoolean(expVar);
    assertTrue(val);
}
Also used : Expression(com.aerospike.client.exp.Expression) 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