Search in sources :

Example 26 with AccumuloElementConversionException

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

the class ByteEntityAccumuloElementConverter method getEntityFromKey.

@Override
protected Entity getEntityFromKey(final Key key, final byte[] row) {
    try {
        final Entity entity = new Entity(getGroupFromKey(key), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(ByteArrayEscapeUtils.unEscape(row, 0, row.length - 2)));
        addPropertiesToElement(entity, key);
        return entity;
    } catch (final SerialisationException e) {
        throw new AccumuloElementConversionException("Failed to re-create Entity from key", e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 27 with AccumuloElementConversionException

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

the class ByteEntityAccumuloElementConverter method getSourceAndDestinationFromRowKey.

@Override
protected EdgeDirection getSourceAndDestinationFromRowKey(final byte[] rowKey, final byte[][] sourceDestValues) {
    // Get element class, sourceValue, destinationValue and directed flag from row key
    // Expect to find 3 delimiters (4 fields)
    final int[] positionsOfDelimiters = new int[3];
    short numDelims = 0;
    // Last byte will be directional flag so don't count it
    for (int i = 0; i < rowKey.length - 1; ++i) {
        if (rowKey[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (numDelims >= 3) {
                throw new AccumuloElementConversionException("Too many delimiters found in row key - found more than the expected 3.");
            }
            positionsOfDelimiters[numDelims++] = i;
        }
    }
    if (numDelims != 3) {
        throw new AccumuloElementConversionException("Wrong number of delimiters found in row key - found " + numDelims + ", expected 3.");
    }
    // If edge is undirected then create edge
    // (no need to worry about which direction the vertices should go in).
    // If the edge is directed then need to decide which way round the vertices should go.
    byte directionFlag;
    try {
        directionFlag = rowKey[rowKey.length - 1];
    } catch (final NumberFormatException e) {
        throw new AccumuloElementConversionException("Error parsing direction flag from row key - " + e);
    }
    byte[] sourceBytes = ByteArrayEscapeUtils.unEscape(rowKey, 0, positionsOfDelimiters[0]);
    byte[] destBytes = ByteArrayEscapeUtils.unEscape(rowKey, positionsOfDelimiters[1] + 1, positionsOfDelimiters[2]);
    EdgeDirection rtn;
    sourceDestValues[0] = sourceBytes;
    sourceDestValues[1] = destBytes;
    switch(directionFlag) {
        case ByteEntityPositions.UNDIRECTED_EDGE:
            // Edge is undirected
            rtn = EdgeDirection.UNDIRECTED;
            break;
        case ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the first identifier is the source of the edge
            rtn = EdgeDirection.DIRECTED;
            break;
        case ByteEntityPositions.INCORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the second identifier is the source of the edge
            sourceDestValues[0] = destBytes;
            sourceDestValues[1] = sourceBytes;
            rtn = EdgeDirection.DIRECTED_REVERSED;
            break;
        default:
            throw new AccumuloElementConversionException("Invalid direction flag in row key - flag was " + directionFlag);
    }
    return rtn;
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 28 with AccumuloElementConversionException

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

the class AddElementsFromHdfsMapper method map.

@Override
protected void map(final Element element, final Context context) throws IOException, InterruptedException {
    final Pair<Key, Key> keyPair;
    try {
        keyPair = elementConverter.getKeysFromElement(element);
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    final Value value;
    try {
        value = elementConverter.getValueFromElement(element);
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    context.write(keyPair.getFirst(), value);
    if (null != keyPair.getSecond()) {
        context.write(keyPair.getSecond(), value);
    }
    context.getCounter("Bulk import", element.getClass().getSimpleName() + " count").increment(1L);
}
Also used : Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 29 with AccumuloElementConversionException

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

the class AggregatorIterator method reduce.

@Override
public Value reduce(final Key key, final Iterator<Value> iter) {
    // Get first Value. If this is the only Value then return it straight
    // away;
    Value value = iter.next();
    if (!iter.hasNext()) {
        return value;
    }
    final String group = elementConverter.getGroupFromColumnFamily(key.getColumnFamilyData().getBackingArray());
    Properties properties;
    final ElementAggregator aggregator = schema.getElement(group).getIngestAggregator();
    try {
        properties = elementConverter.getPropertiesFromValue(group, value);
    } catch (final AccumuloElementConversionException e) {
        throw new AggregationException("Failed to recreate a graph element from a key and value", e);
    }
    Properties aggregatedProps = properties;
    while (iter.hasNext()) {
        value = iter.next();
        try {
            properties = elementConverter.getPropertiesFromValue(group, value);
        } catch (final AccumuloElementConversionException e) {
            throw new AggregationException("Failed to recreate a graph element from a key and value", e);
        }
        aggregatedProps = aggregator.apply(aggregatedProps, properties);
    }
    try {
        return elementConverter.getValueFromProperties(group, aggregatedProps);
    } catch (final AccumuloElementConversionException e) {
        throw new AggregationException("Failed to create an accumulo value from an elements properties", e);
    }
}
Also used : AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) 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