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);
}
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);
}
}
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));
}
}
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());
}
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));
}
Aggregations