Search in sources :

Example 1 with Union

use of org.apache.datasketches.tuple.Union in project sketches-core by DataSketches.

the class AdoubleUnionTest method checkUnionUpdateWithTheta.

@Test
public void checkUnionUpdateWithTheta() {
    final Union<DoubleSummary> union = new Union<>(new DoubleSummarySetOperations(mode, mode));
    UpdateSketch usk = null;
    DoubleSummary dsum = null;
    try {
        union.union(usk, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
    usk = new UpdateSketchBuilder().build();
    try {
        union.union(usk, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
    dsum = new DoubleSummaryFactory(mode).newSummary();
    for (int i = 0; i < 10; i++) {
        usk.update(i);
    }
    union.union(usk, dsum);
    Assert.assertEquals(union.getResult().getEstimate(), 10.0);
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) Union(org.apache.datasketches.tuple.Union) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 2 with Union

use of org.apache.datasketches.tuple.Union in project sketches-core by DataSketches.

the class ArrayOfStringsSketchTest method checkSketch.

@SuppressWarnings("deprecation")
@Test
public void checkSketch() {
    ArrayOfStringsSketch sketch1 = new ArrayOfStringsSketch();
    String[][] strArrArr = { { "a", "b" }, { "c", "d" }, { "e", "f" } };
    int len = strArrArr.length;
    for (int i = 0; i < len; i++) {
        sketch1.update(strArrArr[i], strArrArr[i]);
    }
    // insert duplicate
    sketch1.update(strArrArr[0], strArrArr[0]);
    // printSummaries(sketch1.iterator());
    byte[] array = sketch1.toByteArray();
    WritableMemory wmem = WritableMemory.writableWrap(array);
    ArrayOfStringsSketch sketch2 = new ArrayOfStringsSketch(wmem);
    // printSummaries(sketch2.iterator());
    checkSummaries(sketch2, sketch2);
    String[] strArr3 = { "g", "h" };
    sketch2.update(strArr3, strArr3);
    Union<ArrayOfStringsSummary> union = new Union<>(new ArrayOfStringsSummarySetOperations());
    union.union(sketch1);
    union.union(sketch2);
    CompactSketch<ArrayOfStringsSummary> csk = union.getResult();
    // printSummaries(csk.iterator());
    assertEquals(csk.getRetainedEntries(), 4);
    Intersection<ArrayOfStringsSummary> inter = new Intersection<>(new ArrayOfStringsSummarySetOperations());
    inter.intersect(sketch1);
    inter.intersect(sketch2);
    csk = inter.getResult();
    assertEquals(csk.getRetainedEntries(), 3);
    AnotB<ArrayOfStringsSummary> aNotB = new AnotB<>();
    aNotB.setA(sketch2);
    aNotB.notB(sketch1);
    csk = aNotB.getResult(true);
    assertEquals(csk.getRetainedEntries(), 1);
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) Union(org.apache.datasketches.tuple.Union) AnotB(org.apache.datasketches.tuple.AnotB) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

Union (org.apache.datasketches.tuple.Union)2 Test (org.testng.annotations.Test)2 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)1 WritableMemory (org.apache.datasketches.memory.WritableMemory)1 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)1 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)1 AnotB (org.apache.datasketches.tuple.AnotB)1 Intersection (org.apache.datasketches.tuple.Intersection)1