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