Search in sources :

Example 61 with SketchesArgumentException

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

the class SetOperation method wrap.

/**
 * Wrap takes the SetOperation image in Memory and refers to it directly.
 * There is no data copying onto the java heap.
 *
 * <p>Note: Only certain set operators during stateful operations can be serialized and thus
 * wrapped.</p>
 *
 * @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
 * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
 * @param expectedSeed the seed used to validate the given Memory image.
 * <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
 * @return a SetOperation backed by the given Memory
 */
public static SetOperation wrap(final WritableMemory srcMem, final long expectedSeed) {
    final byte famID = srcMem.getByte(FAMILY_BYTE);
    final Family family = idToFamily(famID);
    final int serVer = srcMem.getByte(SER_VER_BYTE);
    if (serVer != 3) {
        throw new SketchesArgumentException("SerVer must be 3: " + serVer);
    }
    switch(family) {
        case UNION:
            {
                return UnionImpl.wrapInstance(srcMem, expectedSeed);
            }
        case INTERSECTION:
            {
                return IntersectionImpl.wrapInstance(srcMem, expectedSeed, false);
            }
        default:
            throw new SketchesArgumentException("SetOperation cannot wrap family: " + family.toString());
    }
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) Family.idToFamily(org.apache.datasketches.Family.idToFamily) Family(org.apache.datasketches.Family)

Example 62 with SketchesArgumentException

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

the class SetOperation method wrap.

/**
 * Wrap takes the SetOperation image in Memory and refers to it directly.
 * There is no data copying onto the java heap.
 *
 * <p>Note: Only certain set operators during stateful operations can be serialized and thus
 * wrapped.</p>
 *
 * @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
 * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
 * @param expectedSeed the seed used to validate the given Memory image.
 * <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
 * @return a SetOperation backed by the given Memory
 */
public static SetOperation wrap(final Memory srcMem, final long expectedSeed) {
    final byte famID = srcMem.getByte(FAMILY_BYTE);
    final Family family = idToFamily(famID);
    final int serVer = srcMem.getByte(SER_VER_BYTE);
    if (serVer != 3) {
        throw new SketchesArgumentException("SerVer must be 3: " + serVer);
    }
    switch(family) {
        case UNION:
            {
                return UnionImpl.wrapInstance(srcMem, expectedSeed);
            }
        case INTERSECTION:
            {
                return IntersectionImpl.wrapInstance((WritableMemory) srcMem, expectedSeed, true);
            }
        default:
            throw new SketchesArgumentException("SetOperation cannot wrap family: " + family.toString());
    }
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) Family.idToFamily(org.apache.datasketches.Family.idToFamily) Family(org.apache.datasketches.Family) WritableMemory(org.apache.datasketches.memory.WritableMemory)

Example 63 with SketchesArgumentException

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

the class HeapArrayOfDoublesUnion method heapifyUnion.

/**
 * This is to create an instance given a serialized form and a custom seed
 * @param mem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
 * @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
 * @return a ArrayOfDoublesUnion on the Java heap
 */
static ArrayOfDoublesUnion heapifyUnion(final Memory mem, final long seed) {
    final byte version = mem.getByte(SERIAL_VERSION_BYTE);
    if (version != serialVersionUID) {
        throw new SketchesArgumentException("Serial version mismatch. Expected: " + serialVersionUID + ", actual: " + version);
    }
    SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
    SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE), SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
    final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
    final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(sketchMem, seed);
    return new HeapArrayOfDoublesUnion(sketch, mem.getLong(THETA_LONG));
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) Memory(org.apache.datasketches.memory.Memory)

Example 64 with SketchesArgumentException

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

the class DirectArrayOfDoublesUnion method wrapUnion.

static ArrayOfDoublesUnion wrapUnion(final WritableMemory mem, final long seed, final boolean isWritable) {
    final byte version = mem.getByte(ArrayOfDoublesUnion.SERIAL_VERSION_BYTE);
    if (version != ArrayOfDoublesUnion.serialVersionUID) {
        throw new SketchesArgumentException("Serial version mismatch. Expected: " + serialVersionUID + ", actual: " + version);
    }
    SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
    SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE), SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
    if (isWritable) {
        final WritableMemory sketchMem = mem.writableRegion(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
        return new DirectArrayOfDoublesUnion(new DirectArrayOfDoublesQuickSelectSketch(sketchMem, seed), mem);
    }
    final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
    return new DirectArrayOfDoublesUnionR(new DirectArrayOfDoublesQuickSelectSketchR(sketchMem, seed), mem);
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) WritableMemory(org.apache.datasketches.memory.WritableMemory)

Aggregations

SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)64 WritableMemory (org.apache.datasketches.memory.WritableMemory)38 Test (org.testng.annotations.Test)29 Family (org.apache.datasketches.Family)14 Memory (org.apache.datasketches.memory.Memory)13 Family.idToFamily (org.apache.datasketches.Family.idToFamily)10 SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)7 WritableHandle (org.apache.datasketches.memory.WritableHandle)6 ResizeFactor (org.apache.datasketches.ResizeFactor)5 ArrayOfLongsSerDe (org.apache.datasketches.ArrayOfLongsSerDe)4 AnotbAction (org.apache.datasketches.SetOperationCornerCases.AnotbAction)3 CornerCase (org.apache.datasketches.SetOperationCornerCases.CornerCase)3 PreambleUtil.extractResizeFactor (org.apache.datasketches.sampling.PreambleUtil.extractResizeFactor)3 ArrayList (java.util.ArrayList)2 SketchesStateException (org.apache.datasketches.SketchesStateException)2 PreambleUtil.insertLgResizeFactor (org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor)2 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)2 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)2 BigDecimal (java.math.BigDecimal)1 ArrayOfBooleansSerDe (org.apache.datasketches.ArrayOfBooleansSerDe)1