Search in sources :

Example 16 with ToBytesSerialiser

use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.

the class MultiSerialiserStorageTest method checkBasicPut.

private void checkBasicPut() throws GafferCheckedException {
    assertEquals((Object) BYTE, mss.getKeyFromValue(VALUE));
    ToBytesSerialiser actualClassFromByte = mss.getSerialiserFromKey(BYTE);
    assertNotNull(actualClassFromByte, "Byte key not found");
    assertEquals(SERIALISER_CLASS, actualClassFromByte, "Wrong SerialiserClass returned for key");
    ToBytesSerialiser actualClassFromValue = mss.getSerialiserFromValue(Integer.MAX_VALUE);
    assertNotNull(actualClassFromValue, "Value class not found");
    assertEquals(SERIALISER_CLASS, actualClassFromValue, "Wrong SerialiserClass returned for value class");
}
Also used : ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)

Example 17 with ToBytesSerialiser

use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method addDeserialisedProperty.

private int addDeserialisedProperty(final byte[] bytes, final int carriage, final Properties properties, final SchemaElementDefinition elementDefinition, final String propertyName) throws SerialisationException {
    int rtn = carriage;
    final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
    final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
    if (null != serialiser) {
        final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[rtn]);
        final int currentPropLength = getCurrentPropLength(bytes, rtn);
        int from = rtn += numBytesForLength;
        rtn += currentPropLength;
        Object deserialisedObject = getDeserialisedObject(serialiser, bytes, from, currentPropLength);
        properties.put(propertyName, deserialisedObject);
    }
    return rtn;
}
Also used : ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 18 with ToBytesSerialiser

use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.

@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) {
    final Properties properties = new Properties();
    final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
            try {
                if (null == columnVisibility || columnVisibility.length == 0) {
                    final Object value = serialiser.deserialiseEmpty();
                    if (null != value) {
                        properties.put(schema.getVisibilityProperty(), value);
                    }
                } else {
                    properties.put(schema.getVisibilityProperty(), serialiser.deserialise(columnVisibility));
                }
            } catch (final SerialisationException e) {
                throw new AccumuloElementConversionException(e.getMessage(), e);
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 19 with ToBytesSerialiser

use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method buildColumnVisibility.

@Override
public byte[] buildColumnVisibility(final String group, final Properties properties) {
    byte[] rtn = AccumuloStoreConstants.EMPTY_BYTES;
    final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final Object property = properties.get(schema.getVisibilityProperty());
            final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
            if (null != property) {
                try {
                    rtn = serialiser.serialise(property);
                } catch (final SerialisationException e) {
                    throw new AccumuloElementConversionException(e.getMessage(), e);
                }
            } else {
                rtn = serialiser.serialiseNull();
            }
        }
    }
    return rtn;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 20 with ToBytesSerialiser

use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.

the class ClassicRangeFactory method getRange.

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

Aggregations

ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)23 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)14 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)10 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)7 IOException (java.io.IOException)4 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)4 Test (org.junit.jupiter.api.Test)3 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Key (org.apache.accumulo.core.data.Key)2 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)2 LengthValueBytesSerialiserUtil (uk.gov.gchq.gaffer.serialisation.util.LengthValueBytesSerialiserUtil)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Range (org.apache.accumulo.core.data.Range)1