use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnOrderedSerialiserForAnInteger.
@Test
public void shouldReturnOrderedSerialiserForAnInteger() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = Integer.class;
final boolean ordered = true;
// When
final Serialisation serialiser = factory.getSerialiser(clazz, ordered);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(RawIntegerSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnSerialiserForAnInteger.
@Test
public void shouldReturnSerialiserForAnInteger() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = Integer.class;
// When
final Serialisation serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(CompactRawIntegerSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnSerialiserForAString.
@Test
public void shouldReturnSerialiserForAString() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = String.class;
// When
final Serialisation serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(StringSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method buildColumnQualifier.
@Override
public byte[] buildColumnQualifier(final String group, final Properties properties) throws AccumuloElementConversionException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final SchemaElementDefinition elementDefinition = schema.getElement(group);
if (null == elementDefinition) {
throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
}
final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
while (propertyNames.hasNext()) {
String propertyName = propertyNames.next();
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final Serialisation serialiser = (typeDefinition != null) ? typeDefinition.getSerialiser() : null;
try {
if (null != serialiser) {
Object value = properties.get(propertyName);
if (null != value) {
final byte[] bytes = serialiser.serialise(value);
writeBytes(bytes, out);
} else {
final byte[] bytes = serialiser.serialiseNull();
writeBytes(bytes, out);
}
} else {
writeBytes(AccumuloStoreConstants.EMPTY_BYTES, out);
}
} catch (final IOException e) {
throw new AccumuloElementConversionException("Failed to write serialise property to ByteArrayOutputStream" + propertyName, e);
}
}
return out.toByteArray();
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation 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);
}
Aggregations