Search in sources :

Example 6 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method operateSetUnionFlags.

@Test
public void operateSetUnionFlags() {
    int nIndexBits = 6;
    int lowNBits = 4;
    int highNBits = 8;
    String otherName = binName + "o";
    // Keep record around win binName is removed.
    ArrayList<HLLValue> hlls = new ArrayList<HLLValue>();
    Record record = assertSuccess("other bin", key, Operation.delete(), HLLOperation.add(HLLPolicy.Default, otherName, entries, nIndexBits), Operation.get(otherName));
    List<?> resultList = record.getList(otherName);
    HLLValue hll = (HLLValue) resultList.get(1);
    hlls.add(hll);
    // create_only
    HLLPolicy c = new HLLPolicy(HLLWriteFlags.CREATE_ONLY);
    assertSuccess("create_only", key, HLLOperation.setUnion(c, binName, hlls));
    assertThrows("create_only - error", key, AerospikeException.class, ResultCode.BIN_EXISTS_ERROR, HLLOperation.setUnion(c, binName, hlls));
    // update_only
    HLLPolicy u = new HLLPolicy(HLLWriteFlags.UPDATE_ONLY);
    assertSuccess("update_only", key, HLLOperation.setUnion(u, binName, hlls));
    assertSuccess("remove bin", key, Operation.put(Bin.asNull(binName)));
    assertThrows("update_only - error", key, AerospikeException.class, ResultCode.BIN_NOT_FOUND, HLLOperation.setUnion(u, binName, hlls));
    // create_only no_fail
    HLLPolicy cn = new HLLPolicy(HLLWriteFlags.CREATE_ONLY | HLLWriteFlags.NO_FAIL);
    assertSuccess("create_only nofail", key, HLLOperation.setUnion(cn, binName, hlls));
    assertSuccess("create_only nofail - no error", key, HLLOperation.setUnion(cn, binName, hlls));
    // update_only no_fail
    HLLPolicy un = new HLLPolicy(HLLWriteFlags.UPDATE_ONLY | HLLWriteFlags.NO_FAIL);
    assertSuccess("update_only nofail", key, HLLOperation.setUnion(un, binName, hlls));
    assertSuccess("remove bin", key, Operation.put(Bin.asNull(binName)));
    assertSuccess("update_only nofail - no error", key, HLLOperation.setUnion(un, binName, hlls));
    // fold
    HLLPolicy f = new HLLPolicy(HLLWriteFlags.ALLOW_FOLD);
    // fold down
    assertSuccess("size up", key, HLLOperation.init(HLLPolicy.Default, binName, highNBits));
    assertSuccess("fold down to index_bits", key, HLLOperation.setUnion(f, binName, hlls));
    // fold up
    assertSuccess("size down", key, HLLOperation.init(HLLPolicy.Default, binName, lowNBits));
    assertSuccess("fold down to low_n_bits", key, HLLOperation.setUnion(f, binName, hlls));
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) HLLPolicy(com.aerospike.client.operation.HLLPolicy) Test(org.junit.Test)

Example 7 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy 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 8 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method badReInit.

@Test
public void badReInit() {
    HLLPolicy p = HLLPolicy.Default;
    assertSuccess("create min max", key, Operation.delete(), HLLOperation.init(p, binName, maxNIndexBits, 0));
    assertThrows("create_only", key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, HLLOperation.init(p, binName, -1, maxNMinhashBits));
}
Also used : HLLPolicy(com.aerospike.client.operation.HLLPolicy) Test(org.junit.Test)

Aggregations

HLLPolicy (com.aerospike.client.operation.HLLPolicy)8 Record (com.aerospike.client.Record)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Operation (com.aerospike.client.Operation)3 HLLOperation (com.aerospike.client.operation.HLLOperation)3 List (java.util.List)3 HLLValue (com.aerospike.client.Value.HLLValue)2 Value (com.aerospike.client.Value)1 StringValue (com.aerospike.client.Value.StringValue)1