Search in sources :

Example 1 with Serialisation

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());
}
Also used : Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Test(org.junit.Test)

Example 2 with Serialisation

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());
}
Also used : Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Test(org.junit.Test)

Example 3 with Serialisation

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());
}
Also used : Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Test(org.junit.Test)

Example 4 with Serialisation

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();
}
Also used : Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 5 with Serialisation

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

Aggregations

Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)15 Test (org.junit.Test)8 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)3 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 Key (org.apache.accumulo.core.data.Key)2 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)2 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Value (org.apache.accumulo.core.data.Value)1 Properties (uk.gov.gchq.gaffer.data.element.Properties)1 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)1