Search in sources :

Example 11 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ByteEntityRangeFactory method getKeyFromEdgeSeed.

@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
    final Serialisation vertexSerialiser = schema.getVertexSerialiser();
    final byte directionFlag1 = seed.isDirected() ? ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE : ByteEntityPositions.UNDIRECTED_EDGE;
    byte[] sourceValue;
    try {
        sourceValue = ByteArrayEscapeUtils.escape((vertexSerialiser.serialise(seed.getSource())));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Source", e);
    }
    byte[] destinationValue;
    try {
        destinationValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Destination", e);
    }
    int length;
    byte[] key;
    if (endKey) {
        length = sourceValue.length + destinationValue.length + 6;
        key = new byte[length];
        key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 2] = directionFlag1;
        key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    } else {
        length = sourceValue.length + destinationValue.length + 5;
        key = new byte[length];
        key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 1] = directionFlag1;
    }
    System.arraycopy(sourceValue, 0, key, 0, sourceValue.length);
    key[sourceValue.length] = ByteArrayEscapeUtils.DELIMITER;
    key[sourceValue.length + 1] = directionFlag1;
    key[sourceValue.length + 2] = ByteArrayEscapeUtils.DELIMITER;
    System.arraycopy(destinationValue, 0, key, sourceValue.length + 3, destinationValue.length);
    return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Key(org.apache.accumulo.core.data.Key) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 12 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ClassicAccumuloElementConverter method getEntityFromKey.

@Override
protected Entity getEntityFromKey(final Key key) throws AccumuloElementConversionException {
    try {
        final Entity entity = new Entity(getGroupFromKey((key)), getVertexSerialiser().deserialise(ByteArrayEscapeUtils.unEscape(key.getRowData().getBackingArray())));
        addPropertiesToElement(entity, key);
        return entity;
    } catch (final SerialisationException e) {
        throw new AccumuloElementConversionException("Failed to re-create Entity from key", e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 13 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ClassicRangeFactory method getRange.

@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
    final IncludeEdgeType includeEdges;
    final boolean includeEntities;
    if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
        includeEdges = IncludeEdgeType.NONE;
        includeEntities = true;
    } else {
        includeEdges = includeEdgesParam;
        includeEntities = operation.isIncludeEntities();
    }
    byte[] serialisedVertex;
    try {
        serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise identifier", e);
    }
    final boolean returnEdges = includeEdges != IncludeEdgeType.NONE;
    if (!includeEntities && !returnEdges) {
        throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range from a type and value");
    }
    if (includeEntities && returnEdges) {
        return Collections.singletonList(getRange(serialisedVertex));
    } else if (includeEntities) {
        return Collections.singletonList(getEntityRangeFromVertex(serialisedVertex));
    } else {
        return Collections.singletonList(getEdgeRangeFromVertex(serialisedVertex));
    }
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 14 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class HyperLogLogPlusSerialiserTest method testSerialiseAndDeserialise.

@Test
public void testSerialiseAndDeserialise() {
    final HyperLogLogPlus hyperLogLogPlus1 = new HyperLogLogPlus(5, 5);
    hyperLogLogPlus1.offer("A");
    hyperLogLogPlus1.offer("B");
    long hyperLogLogPlus1PreSerialisationCardinality = hyperLogLogPlus1.cardinality();
    final byte[] hyperLogLogPlus1Serialised;
    try {
        hyperLogLogPlus1Serialised = HYPER_LOG_LOG_PLUS_SERIALISER.serialise(hyperLogLogPlus1);
    } catch (SerialisationException exception) {
        fail("A Serialisation Exception Occurred");
        return;
    }
    final HyperLogLogPlus hyperLogLogPlus1Deserialised;
    try {
        hyperLogLogPlus1Deserialised = HYPER_LOG_LOG_PLUS_SERIALISER.deserialise(hyperLogLogPlus1Serialised);
    } catch (SerialisationException exception) {
        fail("A Serialisation Exception Occurred");
        return;
    }
    assertEquals(hyperLogLogPlus1PreSerialisationCardinality, hyperLogLogPlus1Deserialised.cardinality());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Test(org.junit.Test)

Example 15 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class LongsSketchSerialiserTest method testSerialiser.

private void testSerialiser(final LongsSketch sketch) {
    final long freqOf1 = sketch.getEstimate(1L);
    final byte[] sketchSerialised;
    try {
        sketchSerialised = SERIALISER.serialise(sketch);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final LongsSketch sketchDeserialised;
    try {
        sketchDeserialised = SERIALISER.deserialise(sketchSerialised);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    assertEquals(freqOf1, sketchDeserialised.getEstimate(1L));
}
Also used : LongsSketch(com.yahoo.sketches.frequencies.LongsSketch) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException)

Aggregations

SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)39 IOException (java.io.IOException)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Entry (java.util.Map.Entry)2 Key (org.apache.accumulo.core.data.Key)2 Test (org.junit.Test)2 RoaringBitmap (org.roaringbitmap.RoaringBitmap)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2