Search in sources :

Example 21 with AccumuloElementConversionException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.

the class Gaffer1BloomElementFunctorTest method shouldTransformRangeWhenUsingRangeNotExact.

@Test
public void shouldTransformRangeWhenUsingRangeNotExact() {
    try {
        // Create SimpleEntity
        final Entity simpleEntity = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
        final Key key = elementConverter.getKeyFromEntity(simpleEntity);
        final Range range = Range.exact(key.getRow());
        final org.apache.hadoop.util.bloom.Key expectedBloomKey1 = new org.apache.hadoop.util.bloom.Key(ELEMENT_FUNCTOR.getVertexFromRangeKey(key.getRowData().getBackingArray()));
        assertNotNull(ELEMENT_FUNCTOR.transform(range));
        assertEquals(expectedBloomKey1, ELEMENT_FUNCTOR.transform(range));
    } catch (final AccumuloElementConversionException e) {
        fail("ConversionException " + e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) Test(org.junit.jupiter.api.Test)

Example 22 with AccumuloElementConversionException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method getEdgeFromKey.

@SuppressWarnings("WeakerAccess")
protected Edge getEdgeFromKey(final Key key, final byte[] row, final boolean includeMatchedVertex) {
    final byte[][] result = new byte[2][];
    final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
    final EdgeId.MatchedVertex matchedVertex;
    if (!includeMatchedVertex) {
        matchedVertex = null;
    } else if (EdgeDirection.DIRECTED_REVERSED == direction) {
        matchedVertex = EdgeId.MatchedVertex.DESTINATION;
    } else {
        matchedVertex = EdgeId.MatchedVertex.SOURCE;
    }
    final String group = getGroupFromColumnFamily(key.getColumnFamilyData().getBackingArray());
    try {
        final Edge edge = new Edge(group, ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex, null);
        addPropertiesToElement(edge, key);
        return edge;
    } catch (final SerialisationException e) {
        throw new AccumuloElementConversionException("Failed to re-create Edge from key", e);
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) Edge(uk.gov.gchq.gaffer.data.element.Edge) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 23 with AccumuloElementConversionException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method getEdgeId.

protected EdgeId getEdgeId(final byte[] row, final boolean includeMatchedVertex) {
    final byte[][] result = new byte[2][];
    final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
    final EdgeId.MatchedVertex matchedVertex;
    if (!includeMatchedVertex) {
        matchedVertex = null;
    } else if (EdgeDirection.DIRECTED_REVERSED == direction) {
        matchedVertex = EdgeId.MatchedVertex.DESTINATION;
    } else {
        matchedVertex = EdgeId.MatchedVertex.SOURCE;
    }
    try {
        return new EdgeSeed(((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex);
    } catch (final SerialisationException e) {
        throw new AccumuloElementConversionException("Failed to create EdgeId from Accumulo row key", e);
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 24 with AccumuloElementConversionException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException 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 25 with AccumuloElementConversionException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException 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)

Aggregations

AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)29 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)12 Key (org.apache.accumulo.core.data.Key)11 Properties (uk.gov.gchq.gaffer.data.element.Properties)7 Value (org.apache.accumulo.core.data.Value)6 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 Range (org.apache.accumulo.core.data.Range)4 Test (org.junit.jupiter.api.Test)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 EdgeDirection (uk.gov.gchq.gaffer.data.element.EdgeDirection)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 Mutation (org.apache.accumulo.core.data.Mutation)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 GafferRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)2