use of uk.gov.gchq.gaffer.data.element.id.EdgeId in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeId.
@Test
public void shouldDeserialiseEdgeId() {
// Given
final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
final Edge edge = new Edge.Builder().source("source1").dest("dest1").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeysFromEdge(edge).getFirst();
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.data.element.id.EdgeId in project Gaffer by gchq.
the class FullSchemaLoader method createEdges.
@Override
public Map<EdgeId, Edge> createEdges() {
final Map<EdgeId, Edge> edges = new HashMap<>();
for (int i = 0; i <= 10; i++) {
for (int j = 0; j < VERTEX_PREFIXES.length; j++) {
final FreqMap freqMap = new FreqMap();
freqMap.upsert("key");
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(VERTEX_PREFIXES[0] + i).dest(VERTEX_PREFIXES[j] + i).directed(false).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "public").build();
addToMap(edge, edges);
final FreqMap freqMap2 = new FreqMap();
freqMap2.upsert("key");
final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(VERTEX_PREFIXES[0] + i).dest(VERTEX_PREFIXES[j] + i).directed(true).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap2).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "private").build();
addToMap(edgeDir, edges);
}
final FreqMap freqMap3 = new FreqMap();
freqMap3.upsert("key");
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(SOURCE + i).dest(DEST + i).directed(false).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap3).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "public").build();
addToMap(edge, edges);
final FreqMap freqMap4 = new FreqMap();
freqMap4.upsert("key");
final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(SOURCE_DIR + i).dest(DEST_DIR + i).directed(true).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap4).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "private").build();
addToMap(edgeDir, edges);
}
return edges;
}
use of uk.gov.gchq.gaffer.data.element.id.EdgeId in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getEdgeId.
protected EdgeId getEdgeId(final byte[] row, final boolean includeMatchedVertex) {
final byte[][] result = new byte[2][];
final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
final EdgeId.MatchedVertex matchedVertex;
if (!includeMatchedVertex) {
matchedVertex = null;
} else if (EdgeDirection.DIRECTED_REVERSED == direction) {
matchedVertex = EdgeId.MatchedVertex.DESTINATION;
} else {
matchedVertex = EdgeId.MatchedVertex.SOURCE;
}
try {
return new EdgeSeed(((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex);
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to create EdgeId from Accumulo row key", e);
}
}
use of uk.gov.gchq.gaffer.data.element.id.EdgeId in project Gaffer by gchq.
the class AbstractCoreKeyRangeFactory method getRange.
private List<Range> getRange(final ElementId elementId, final GraphFilters operation, final SeededGraphFilters.IncludeIncomingOutgoingType inOutType) throws RangeFactoryException {
if (elementId instanceof EntityId) {
return getRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
} else {
final EdgeId edgeId = (EdgeId) elementId;
final List<Range> ranges = new ArrayList<>();
if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
// EQUALS and RELATED seed matching.
final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
ranges.addAll(getRange(edgeId.getSource(), edgeId.getDestination(), directed, operation, inOutType));
}
// Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatching.SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
if (doRelated && operation.getView().hasEntities()) {
// Get Entities related to EdgeIds
ranges.addAll(getRange(edgeId.getSource(), operation, false));
ranges.addAll(getRange(edgeId.getDestination(), operation, false));
}
return ranges;
}
}
use of uk.gov.gchq.gaffer.data.element.id.EdgeId in project Gaffer by gchq.
the class RowRangeFactory method getRowRange.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge")
public List<RowRange> getRowRange(final ElementId elementId, final GraphFilters operation) throws SerialisationException {
if (elementId instanceof EntityId) {
return getRowRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
} else {
final EdgeId edgeId = (EdgeId) elementId;
final List<RowRange> ranges = new ArrayList<>();
if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
// Get Edges with the given EdgeSeed - This is applicable for
// EQUALS and RELATED seed matching.
final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
// To do that we need to create 2 ranges
if (DirectedType.isEither(directed)) {
ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, true), true));
ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, true), true));
} else {
ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), true), true));
}
}
// Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
if (doRelated && operation.getView().hasEntities()) {
// Get Entities related to EdgeIds
ranges.addAll(getRowRange(edgeId.getSource(), operation, false));
ranges.addAll(getRowRange(edgeId.getDestination(), operation, false));
}
return ranges;
}
}
Aggregations