Search in sources :

Example 6 with HLLValue

use of com.aerospike.client.Value.HLLValue in project aerospike-client-java by aerospike.

the class TestOperateHll method assertSetUnion.

public void assertSetUnion(List<List<Value>> vals, int nIndexBits, boolean folding, boolean allowFolding) {
    String msg = "Fail - nIndexBits " + nIndexBits;
    HLLPolicy p = HLLPolicy.Default;
    HLLPolicy u = HLLPolicy.Default;
    if (allowFolding) {
        u = new HLLPolicy(HLLWriteFlags.ALLOW_FOLD);
    }
    long unionExpected = 0;
    boolean folded = false;
    for (int i = 0; i < keys.length; i++) {
        int ix = nIndexBits;
        if (folding) {
            ix -= i;
            if (ix < minNIndexBits) {
                ix = minNIndexBits;
            }
            if (ix < nIndexBits) {
                folded = true;
            }
        }
        List<Value> subVals = vals.get(i);
        unionExpected += subVals.size();
        Record record = assertSuccess(msg, keys[i], Operation.delete(), HLLOperation.add(p, binName, subVals, ix), HLLOperation.getCount(binName));
        List<?> resultList = record.getList(binName);
        long count = (Long) resultList.get(1);
        assertHLLCount(msg, ix, count, subVals.size());
    }
    ArrayList<HLLValue> hlls = new ArrayList<HLLValue>();
    for (int i = 0; i < keys.length; i++) {
        Record record = assertSuccess(msg, keys[i], Operation.get(binName), HLLOperation.getCount(binName));
        List<?> resultList = record.getList(binName);
        HLLValue hll = (HLLValue) resultList.get(0);
        assertNotEquals(null, hll);
        hlls.add(hll);
    }
    Operation[] ops = new Operation[] { Operation.delete(), HLLOperation.init(p, binName, nIndexBits), HLLOperation.setUnion(u, binName, hlls), HLLOperation.getCount(binName), // And recreate it to test creating empty.
    Operation.delete(), HLLOperation.setUnion(p, binName, hlls), HLLOperation.getCount(binName) };
    if (folded && !allowFolding) {
        assertThrows(msg, key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, ops);
        return;
    }
    Record recordUnion = assertSuccess(msg, key, ops);
    List<?> unionResultList = recordUnion.getList(binName);
    long unionCount = (Long) unionResultList.get(2);
    long unionCount2 = (Long) unionResultList.get(4);
    assertHLLCount(msg, nIndexBits, unionCount, unionExpected);
    assertEquals(msg, unionCount, unionCount2);
    for (int i = 0; i < keys.length; i++) {
        List<Value> subVals = vals.get(i);
        Record record = assertSuccess(msg, key, HLLOperation.add(p, binName, subVals, nIndexBits), HLLOperation.getCount(binName));
        List<?> resultList = record.getList(binName);
        long nAdded = (Long) resultList.get(0);
        long count = (Long) resultList.get(1);
        assertEquals(msg, 0, nAdded);
        assertEquals(msg, unionCount, count);
        assertHLLCount(msg, nIndexBits, count, unionExpected);
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Operation(com.aerospike.client.Operation) HLLOperation(com.aerospike.client.operation.HLLOperation) HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Example 7 with HLLValue

use of com.aerospike.client.Value.HLLValue in project aerospike-client-java by aerospike.

the class TestOperateHll method getPut.

@Test
public void getPut() {
    for (ArrayList<Integer> desc : legalDescriptions) {
        int nIndexBits = desc.get(0);
        int nMinhashBits = desc.get(1);
        assertSuccess("init record", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName, nIndexBits, nMinhashBits));
        Record record = client.get(null, key);
        HLLValue hll = (HLLValue) record.getHLLValue(binName);
        client.delete(null, key);
        client.put(null, key, new Bin(binName, hll));
        record = assertSuccess("describe", key, HLLOperation.getCount(binName), HLLOperation.describe(binName));
        List<?> resultList = record.getList(binName);
        long count = (Long) resultList.get(0);
        List<?> description = (List<?>) resultList.get(1);
        assertEquals(0, count);
        assertDescription("Check description", description, nIndexBits, nMinhashBits);
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with HLLValue

use of com.aerospike.client.Value.HLLValue in project aerospike-client-java by aerospike.

the class TestOperateHll method assertSimilarityOp.

public void assertSimilarityOp(double overlap, List<Value> common, List<List<Value>> vals, int nIndexBits, int nMinhashBits) {
    List<HLLValue> hlls = new ArrayList<HLLValue>();
    for (int i = 0; i < keys.length; i++) {
        Record record = assertSuccess("init other keys", keys[i], Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, vals.get(i), nIndexBits, nMinhashBits), HLLOperation.add(HLLPolicy.Default, binName, common, nIndexBits, nMinhashBits), Operation.get(binName));
        List<?> resultList = record.getList(binName);
        hlls.add((HLLValue) resultList.get(2));
    }
    // Keep record around win binName is removed.
    Record record = assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits, nMinhashBits), HLLOperation.setUnion(HLLPolicy.Default, binName, hlls), HLLOperation.describe(binName));
    List<?> resultList = record.getList(binName);
    List<?> description = (List<?>) resultList.get(1);
    assertDescription("check desc", description, nIndexBits, nMinhashBits);
    record = assertSuccess("similarity and intersectCount", 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);
    double expectedSimilarity = overlap;
    long expectedIntersectCount = common.size();
    assertHMHSimilarity("check sim", nIndexBits, nMinhashBits, sim, expectedSimilarity, intersectCount, expectedIntersectCount);
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with HLLValue

use of com.aerospike.client.Value.HLLValue in project aerospike-client-java by aerospike.

the class TestHLLExp method hllExp.

@Test
public void hllExp() {
    Key key = new Key(args.namespace, args.set, 5200);
    client.delete(null, key);
    ArrayList<Value> list1 = new ArrayList<Value>();
    list1.add(Value.get("Akey1"));
    list1.add(Value.get("Akey2"));
    list1.add(Value.get("Akey3"));
    ArrayList<Value> list2 = new ArrayList<Value>();
    list2.add(Value.get("Bkey1"));
    list2.add(Value.get("Bkey2"));
    list2.add(Value.get("Bkey3"));
    ArrayList<Value> list3 = new ArrayList<Value>();
    list3.add(Value.get("Akey1"));
    list3.add(Value.get("Akey2"));
    list3.add(Value.get("Bkey1"));
    list3.add(Value.get("Bkey2"));
    list3.add(Value.get("Ckey1"));
    list3.add(Value.get("Ckey2"));
    Record rec = client.operate(null, key, HLLOperation.add(HLLPolicy.Default, bin1, list1, 8), HLLOperation.add(HLLPolicy.Default, bin2, list2, 8), HLLOperation.add(HLLPolicy.Default, bin3, list3, 8), Operation.get(bin1), Operation.get(bin2), Operation.get(bin3));
    List<?> results = rec.getList(bin1);
    hll1 = (HLLValue) results.get(1);
    assertNotEquals(null, hll1);
    results = rec.getList(bin2);
    hll2 = (HLLValue) results.get(1);
    assertNotEquals(null, hll2);
    results = rec.getList(bin3);
    hll3 = (HLLValue) results.get(1);
    assertNotEquals(null, hll3);
    count(key);
    union(key);
    intersect(key);
    similarity(key);
    describe(key);
    mayContain(key);
    add(key);
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 10 with HLLValue

use of com.aerospike.client.Value.HLLValue in project aerospike-client-java by aerospike.

the class TestHLLExp method intersect.

private void intersect(Key key) {
    ArrayList<HLLValue> hlls2 = new ArrayList<HLLValue>();
    hlls2.add(hll2);
    ArrayList<HLLValue> hlls3 = new ArrayList<HLLValue>();
    hlls3.add(hll3);
    policy.filterExp = Exp.build(Exp.ge(HLLExp.getIntersectCount(Exp.val(hlls2), Exp.hllBin(bin1)), HLLExp.getIntersectCount(Exp.val(hlls3), Exp.hllBin(bin1))));
    Record r = client.get(policy, key);
    assertEquals(null, r);
    policy.filterExp = Exp.build(Exp.le(HLLExp.getIntersectCount(Exp.val(hlls2), Exp.hllBin(bin1)), HLLExp.getIntersectCount(Exp.val(hlls3), Exp.hllBin(bin1))));
    r = client.get(policy, key);
    assertRecordFound(key, r);
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record)

Aggregations

Record (com.aerospike.client.Record)12 HLLValue (com.aerospike.client.Value.HLLValue)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)7 Value (com.aerospike.client.Value)3 List (java.util.List)3 Bin (com.aerospike.client.Bin)2 StringValue (com.aerospike.client.Value.StringValue)2 HLLPolicy (com.aerospike.client.operation.HLLPolicy)2 Key (com.aerospike.client.Key)1 Operation (com.aerospike.client.Operation)1 Expression (com.aerospike.client.exp.Expression)1 HLLOperation (com.aerospike.client.operation.HLLOperation)1