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