Search in sources :

Example 1 with ArrayOfStringsSerDe

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

the class ItemsSketchTest method serializeStringDeserializeEmpty.

@Test
public void serializeStringDeserializeEmpty() {
    ItemsSketch<String> sketch1 = new ItemsSketch<>(1 << LG_MIN_MAP_SIZE);
    byte[] bytes = sketch1.toByteArray(new ArrayOfStringsSerDe());
    ItemsSketch<String> sketch2 = ItemsSketch.getInstance(Memory.wrap(bytes), new ArrayOfStringsSerDe());
    Assert.assertTrue(sketch2.isEmpty());
    Assert.assertEquals(sketch2.getNumActiveItems(), 0);
    Assert.assertEquals(sketch2.getStreamLength(), 0);
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Test(org.testng.annotations.Test)

Example 2 with ArrayOfStringsSerDe

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

the class ReservoirItemsSketchTest method checkEmptySketch.

@Test
public void checkEmptySketch() {
    final ReservoirItemsSketch<String> ris = ReservoirItemsSketch.newInstance(5);
    assertTrue(ris.getSamples() == null);
    final byte[] sketchBytes = ris.toByteArray(new ArrayOfStringsSerDe());
    final Memory mem = Memory.wrap(sketchBytes);
    // only minPreLongs bytes and should deserialize to empty
    assertEquals(sketchBytes.length, Family.RESERVOIR.getMinPreLongs() << 3);
    final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
    final ReservoirItemsSketch<String> loadedRis = ReservoirItemsSketch.heapify(mem, serDe);
    assertEquals(loadedRis.getNumSamples(), 0);
    println("Empty sketch:");
    println("  Preamble:");
    println(PreambleUtil.preambleToString(mem));
    println("  Sketch:");
    println(ris.toString());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 3 with ArrayOfStringsSerDe

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

the class VarOptItemsSketchTest method checkEmptySketch.

@Test
public void checkEmptySketch() {
    final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(5);
    assertEquals(vis.getN(), 0);
    assertEquals(vis.getNumSamples(), 0);
    assertNull(vis.getSamplesAsArrays());
    assertNull(vis.getSamplesAsArrays(Long.class));
    final byte[] sketchBytes = vis.toByteArray(new ArrayOfStringsSerDe());
    final Memory mem = Memory.wrap(sketchBytes);
    // only minPreLongs bytes and should deserialize to empty
    assertEquals(sketchBytes.length, Family.VAROPT.getMinPreLongs() << 3);
    final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
    final VarOptItemsSketch<String> loadedVis = VarOptItemsSketch.heapify(mem, serDe);
    assertEquals(loadedVis.getNumSamples(), 0);
    println("Empty sketch:");
    println("  Preamble:");
    VarOptItemsSketch.toString(sketchBytes);
    println(VarOptItemsSketch.toString(mem));
    println("  Sketch:");
    println(vis.toString());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 4 with ArrayOfStringsSerDe

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

the class ItemsSketchTest method checkGetInstanceExcep2.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkGetInstanceExcep2() {
    final Memory mem = Memory.wrap(new byte[8]);
    ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 5 with ArrayOfStringsSerDe

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

the class ItemsSketchTest method checkGoodSerDeId.

@Test
public void checkGoodSerDeId() {
    final ItemsSketch<String> sketch = ItemsSketch.getInstance(Comparator.naturalOrder());
    final byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe());
    final Memory mem = Memory.wrap(byteArr);
    // println(PreambleUtil.toString(mem));
    ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

ArrayOfStringsSerDe (org.apache.datasketches.ArrayOfStringsSerDe)20 Test (org.testng.annotations.Test)19 WritableMemory (org.apache.datasketches.memory.WritableMemory)15 Memory (org.apache.datasketches.memory.Memory)10 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)1