Search in sources :

Example 16 with AccumuloElementConversionException

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

the class SampleDataForSplitPointsMapper method map.

@Override
protected void map(final Element element, final Context context) throws IOException, InterruptedException {
    if (Math.random() < proportionToSample) {
        context.getCounter("Split points", "Number sampled").increment(1L);
        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);
        }
    } else {
        context.getCounter("Split points", "Number not sampled").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 17 with AccumuloElementConversionException

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

the class ClassicAccumuloElementConverter 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)));
        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 18 with AccumuloElementConversionException

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

the class ClassicAccumuloElementConverter method getSourceAndDestinationFromRowKey.

@Override
protected EdgeDirection getSourceAndDestinationFromRowKey(final byte[] rowKey, final byte[][] sourceDestValue) {
    // Get sourceValue, destinationValue and directed flag from row key
    // Expect to find 2 delimiters (3 fields)
    final int[] positionsOfDelimiters = new int[2];
    short numDelims = 0;
    for (int i = 0; i < rowKey.length; i++) {
        if (rowKey[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (numDelims >= 2) {
                throw new AccumuloElementConversionException("Too many delimiters found in row key - found more than the expected 2.");
            }
            positionsOfDelimiters[numDelims++] = i;
        }
    }
    if (numDelims != 2) {
        throw new AccumuloElementConversionException("Wrong number of delimiters found in row key - found " + numDelims + ", expected 2.");
    }
    // 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.
    final int directionFlag = rowKey[rowKey.length - 1];
    byte[] sourceBytes = ByteArrayEscapeUtils.unEscape(rowKey, 0, positionsOfDelimiters[0]);
    byte[] destBytes = ByteArrayEscapeUtils.unEscape(rowKey, positionsOfDelimiters[0] + 1, positionsOfDelimiters[1]);
    sourceDestValue[0] = sourceBytes;
    sourceDestValue[1] = destBytes;
    EdgeDirection rtn;
    switch(directionFlag) {
        case ClassicBytePositions.UNDIRECTED_EDGE:
            // Edge is undirected
            rtn = EdgeDirection.UNDIRECTED;
            break;
        case ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the first identifier is the source of the edge
            rtn = EdgeDirection.DIRECTED;
            break;
        case ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the second identifier is the source of the edge
            sourceDestValue[0] = destBytes;
            sourceDestValue[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 19 with AccumuloElementConversionException

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

the class AbstractCoreKeyAccumuloElementConverter method getEdgeFromKey.

protected Edge getEdgeFromKey(final Key key, final Map<String, String> options) throws AccumuloElementConversionException {
    final byte[][] result = new byte[3][];
    final boolean directed = getSourceAndDestinationFromRowKey(key.getRowData().getBackingArray(), result, options);
    String group;
    try {
        group = new String(key.getColumnFamilyData().getBackingArray(), CommonConstants.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        throw new AccumuloElementConversionException(e.getMessage(), e);
    }
    try {
        final Edge edge = new Edge(group, getVertexSerialiser().deserialise(result[0]), getVertexSerialiser().deserialise(result[1]), directed);
        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) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Edge(uk.gov.gchq.gaffer.data.element.Edge) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 20 with AccumuloElementConversionException

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

the class AccumuloKeyValueReducer method reduceMultiValue.

private Value reduceMultiValue(final Key key, final Iterator<Value> iter, final Value firstValue) {
    final String group;
    try {
        group = new String(key.getColumnFamilyData().getBackingArray(), CommonConstants.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    ElementAggregator aggregator;
    Properties firstPropertySet;
    try {
        firstPropertySet = elementConverter.getPropertiesFromValue(group, firstValue);
        aggregator = schema.getElement(group).getAggregator();
        aggregator.aggregate(firstPropertySet);
        while (iter.hasNext()) {
            aggregator.aggregate(elementConverter.getPropertiesFromValue(group, iter.next()));
        }
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException("Failed to get Properties from an accumulo value", e);
    }
    final Properties properties = new Properties();
    aggregator.state(properties);
    try {
        return elementConverter.getValueFromProperties(group, properties);
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException("Failed to get Properties from an accumulo value", e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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