Search in sources :

Example 36 with EdgeId

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);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 37 with EdgeId

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;
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) HashMap(java.util.HashMap) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 38 with EdgeId

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);
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 39 with EdgeId

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;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) Range(org.apache.accumulo.core.data.Range)

Example 40 with EdgeId

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;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)40 Test (org.junit.jupiter.api.Test)27 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)18 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)15 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)14 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8 HashMap (java.util.HashMap)5 Key (org.apache.accumulo.core.data.Key)4 FreqMap (uk.gov.gchq.gaffer.types.FreqMap)4 ArrayList (java.util.ArrayList)3 DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 HashSet (java.util.HashSet)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)2 Collection (java.util.Collection)1