Search in sources :

Example 1 with StringValue

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

the class TestOperateHll method operateSimilarity.

@Test
public void operateSimilarity() {
    double[] overlaps = new double[] { 0.0001, 0.001, 0.01, 0.1, 0.5 };
    for (double overlap : overlaps) {
        long expectedIntersectCount = (long) (nEntries * overlap);
        ArrayList<Value> common = new ArrayList<Value>();
        for (int i = 0; i < expectedIntersectCount; i++) {
            common.add(new StringValue("common" + i));
        }
        ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
        long uniqueEntriesPerNode = (nEntries - expectedIntersectCount) / 3;
        for (int i = 0; i < keys.length; i++) {
            ArrayList<Value> subVals = new ArrayList<Value>();
            for (int j = 0; j < uniqueEntriesPerNode; j++) {
                subVals.add(new StringValue("key" + i + " " + j));
            }
            vals.add(subVals);
        }
        for (ArrayList<Integer> desc : legalDescriptions) {
            int nIndexBits = desc.get(0);
            int nMinhashBits = desc.get(1);
            if (nMinhashBits == 0) {
                continue;
            }
            assertSimilarityOp(overlap, common, vals, nIndexBits, nMinhashBits);
        }
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringValue(com.aerospike.client.Value.StringValue) Test(org.junit.Test)

Example 2 with StringValue

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

the class TestOperateHll method operateFold.

@Test
public void operateFold() {
    List<Value> vals0 = new ArrayList<Value>();
    List<Value> vals1 = new ArrayList<Value>();
    for (int i = 0; i < nEntries / 2; i++) {
        vals0.add(new StringValue("key " + i));
    }
    for (int i = nEntries / 2; i < nEntries; i++) {
        vals1.add(new StringValue("key " + i));
    }
    for (int nIndexBits = 4; nIndexBits < maxNIndexBits; nIndexBits++) {
        assertFold(vals0, vals1, nIndexBits);
    }
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) StringValue(com.aerospike.client.Value.StringValue) Test(org.junit.Test)

Example 3 with StringValue

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

the class TestOperateHll method operateGetUnion.

@Test
public void operateGetUnion() {
    int nIndexBits = 14;
    long expectedUnionCount = 0;
    ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
    List<HLLValue> hlls = new ArrayList<HLLValue>();
    for (int i = 0; i < keys.length; i++) {
        ArrayList<Value> subVals = new ArrayList<Value>();
        for (int j = 0; j < nEntries / 3; j++) {
            subVals.add(new StringValue("key" + i + " " + j));
        }
        Record record = assertSuccess("init other keys", keys[i], Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, subVals, nIndexBits), Operation.get(binName));
        List<?> resultList = record.getList(binName);
        hlls.add((HLLValue) resultList.get(1));
        expectedUnionCount += subVals.size();
        vals.add(subVals);
    }
    // Keep record around win binName is removed.
    assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits), HLLOperation.add(HLLPolicy.Default, binName, vals.get(0), nIndexBits));
    Record record = assertSuccess("union and unionCount", key, HLLOperation.getUnion(binName, hlls), HLLOperation.getUnionCount(binName, hlls));
    List<?> resultList = record.getList(binName);
    long unionCount = (Long) resultList.get(1);
    assertHLLCount("verify union count", nIndexBits, unionCount, expectedUnionCount);
    HLLValue unionHll = (HLLValue) resultList.get(0);
    record = assertSuccess("", key, Operation.put(new Bin(binName, unionHll)), HLLOperation.getCount(binName));
    resultList = record.getList(binName);
    long unionCount2 = (Long) resultList.get(1);
    assertEquals("unions equal", unionCount, unionCount2);
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.aerospike.client.Record) StringValue(com.aerospike.client.Value.StringValue) Test(org.junit.Test)

Example 4 with StringValue

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

the class TestOperateHll method createData.

@BeforeClass
public static void createData() {
    for (int i = 0; i < nEntries; i++) {
        entries.add(new StringValue("key " + i));
    }
    for (int nIndexBits = minNIndexBits; nIndexBits <= maxNIndexBits; nIndexBits += 4) {
        int nCombinedBits = maxNMinhashBits + nIndexBits;
        int maxAllowedNMinhashBits = maxNMinhashBits;
        if (nCombinedBits > 64) {
            maxAllowedNMinhashBits -= nCombinedBits - 64;
        }
        int midNMinhashBits = (maxAllowedNMinhashBits + nIndexBits) / 2;
        ArrayList<Integer> legalZero = new ArrayList<Integer>();
        ArrayList<Integer> legalMin = new ArrayList<Integer>();
        ArrayList<Integer> legalMid = new ArrayList<Integer>();
        ArrayList<Integer> legalMax = new ArrayList<Integer>();
        legalNIndexBits.add(nIndexBits);
        legalZero.add(nIndexBits);
        legalMin.add(nIndexBits);
        legalMid.add(nIndexBits);
        legalMax.add(nIndexBits);
        legalZero.add(0);
        legalMin.add(minNMinhashBits);
        legalMid.add(midNMinhashBits);
        legalMax.add(maxAllowedNMinhashBits);
        legalDescriptions.add(legalZero);
        legalDescriptions.add(legalMin);
        legalDescriptions.add(legalMid);
        legalDescriptions.add(legalMax);
    }
    for (int indexBits = minNIndexBits - 1; indexBits <= maxNIndexBits + 5; indexBits += 4) {
        if (indexBits < minNIndexBits || indexBits > maxNIndexBits) {
            ArrayList<Integer> illegalZero = new ArrayList<Integer>();
            ArrayList<Integer> illegalMin = new ArrayList<Integer>();
            ArrayList<Integer> illegalMax = new ArrayList<Integer>();
            illegalZero.add(indexBits);
            illegalMin.add(indexBits);
            illegalMax.add(indexBits);
            illegalZero.add(0);
            illegalMin.add(minNMinhashBits - 1);
            illegalMax.add(maxNMinhashBits);
            illegalDescriptions.add(illegalZero);
            illegalDescriptions.add(illegalMin);
            illegalDescriptions.add(illegalMax);
        } else {
            ArrayList<Integer> illegalMin = new ArrayList<Integer>();
            ArrayList<Integer> illegalMax = new ArrayList<Integer>();
            ArrayList<Integer> illegalMax1 = new ArrayList<Integer>();
            illegalMin.add(indexBits);
            illegalMax.add(indexBits);
            illegalMin.add(minNMinhashBits - 1);
            illegalMax.add(maxNMinhashBits + 1);
            illegalDescriptions.add(illegalMin);
            illegalDescriptions.add(illegalMax);
            if (indexBits + maxNMinhashBits > 64) {
                illegalMax1.add(indexBits);
                illegalMax1.add(1 + maxNMinhashBits - (64 - (indexBits + maxNMinhashBits)));
                illegalDescriptions.add(illegalMax1);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StringValue(com.aerospike.client.Value.StringValue) BeforeClass(org.junit.BeforeClass)

Example 5 with StringValue

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

the class TestOperateHll method operateSetUnion.

@Test
public void operateSetUnion() {
    ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
    for (int i = 0; i < keys.length; i++) {
        ArrayList<Value> subVals = new ArrayList<Value>();
        for (int j = 0; j < nEntries / 3; j++) {
            subVals.add(new StringValue("key" + i + " " + j));
        }
        vals.add(subVals);
    }
    for (Integer nIndexBits : legalNIndexBits) {
        assertSetUnion(vals, nIndexBits, false, false);
        assertSetUnion(vals, nIndexBits, false, true);
        assertSetUnion(vals, nIndexBits, true, false);
        assertSetUnion(vals, nIndexBits, true, true);
    }
}
Also used : ArrayList(java.util.ArrayList) HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) List(java.util.List) StringValue(com.aerospike.client.Value.StringValue) Test(org.junit.Test)

Aggregations

StringValue (com.aerospike.client.Value.StringValue)5 ArrayList (java.util.ArrayList)5 Value (com.aerospike.client.Value)4 HLLValue (com.aerospike.client.Value.HLLValue)4 Test (org.junit.Test)4 List (java.util.List)3 Bin (com.aerospike.client.Bin)1 Record (com.aerospike.client.Record)1 BeforeClass (org.junit.BeforeClass)1