use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.
the class ByteEntityRangeFactory method getAllEdgeOnlyKeys.
private Pair<Key> getAllEdgeOnlyKeys(final byte[] serialisedVertex) {
final byte[] endKeyBytes = Arrays.copyOf(serialisedVertex, serialisedVertex.length + 3);
endKeyBytes[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER;
endKeyBytes[serialisedVertex.length + 1] = ByteEntityPositions.UNDIRECTED_EDGE;
endKeyBytes[serialisedVertex.length + 2] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
final byte[] startKeyBytes = Arrays.copyOf(serialisedVertex, serialisedVertex.length + 3);
startKeyBytes[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER;
startKeyBytes[serialisedVertex.length + 1] = ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE;
startKeyBytes[serialisedVertex.length + 2] = ByteArrayEscapeUtils.DELIMITER;
return new Pair<>(new Key(startKeyBytes, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE), new Key(endKeyBytes, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE));
}
use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.
the class ClassicRangeFactory method getKeyFromEdgeSeed.
@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
final byte directionFlag1 = seed.isDirected() ? (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING ? ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE : ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE) : ClassicBytePositions.UNDIRECTED_EDGE;
final Serialisation vertexSerialiser = schema.getVertexSerialiser();
// Serialise source and destination to byte arrays, escaping if
// necessary
byte[] source;
try {
source = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getSource()));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Source", e);
}
byte[] destination;
try {
destination = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Destination", e);
}
// Length of row key is the length of the source
// plus the length of the destination
// plus one for the delimiter in between the source and destination
// plus one for the delimiter in between the destination and the direction flag
// plus one for the direction flag at the end.
byte[] key;
if (endKey) {
key = new byte[source.length + destination.length + 4];
key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
key[key.length - 2] = directionFlag1;
key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
} else {
key = new byte[source.length + destination.length + 3];
key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
key[key.length - 1] = directionFlag1;
}
// Create first key: source DELIMITER destination DELIMITER (CORRECT_WAY_DIRECTED_EDGE or UNDIRECTED_EDGE)
// Here if we desire an EdgeID we and the user has asked for incoming
// edges only for related items, we put the destination first so we find the flipped edge's key,
// this key will pass the filter iterators check for incoming edges, but
// the result will be flipped back to the correct edge on the client end conversion
// Simply put when looking up an EDGE ID that ID counts as both incoming
// and outgoing so we use the reversed key when looking up incoming.
byte[] firstValue;
byte[] secondValue;
if (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING) {
firstValue = destination;
secondValue = source;
} else {
firstValue = source;
secondValue = destination;
}
System.arraycopy(firstValue, 0, key, 0, firstValue.length);
key[firstValue.length] = ByteArrayEscapeUtils.DELIMITER;
System.arraycopy(secondValue, 0, key, firstValue.length + 1, secondValue.length);
return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.
the class ClassicRangeFactory method getRange.
private Range getRange(final byte[] serialisedVertex) {
final byte[] endRowKey = new byte[serialisedVertex.length + 1];
System.arraycopy(serialisedVertex, 0, endRowKey, 0, serialisedVertex.length);
endRowKey[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
final Key startKey = new Key(serialisedVertex, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
final Key endKey = new Key(endRowKey, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
return new Range(startKey, true, endKey, false);
}
use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldGetOriginalEdgeWithMatchAsSourceNotSet.
@Test
public void shouldGetOriginalEdgeWithMatchAsSourceNotSet() throws SchemaException, AccumuloElementConversionException, IOException {
// Given
final Edge edge = new Edge(TestGroups.EDGE);
edge.setDestination("2");
edge.setSource("1");
edge.setDirected(true);
edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
final Pair<Key> keys = converter.getKeysFromElement(edge);
final Map<String, String> options = new HashMap<>();
// When
final Edge newEdge = (Edge) converter.getElementFromKey(keys.getSecond(), options);
// Then
assertEquals("1", newEdge.getSource());
assertEquals("2", newEdge.getDestination());
assertEquals(true, newEdge.isDirected());
assertEquals(100, newEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldReturnAccumuloKeyConverterFromCFCQPropertydEntity.
@Test
public void shouldReturnAccumuloKeyConverterFromCFCQPropertydEntity() throws SchemaException, AccumuloElementConversionException, IOException {
// Given
final Entity entity = new Entity(TestGroups.ENTITY);
entity.setVertex("3");
entity.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
// When
final Pair<Key> keys = converter.getKeysFromElement(entity);
final Entity newEntity = (Entity) converter.getElementFromKey(keys.getFirst());
// Then
assertEquals("3", newEntity.getVertex());
assertEquals(100, newEntity.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Aggregations