Search in sources :

Example 21 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class GetAdjacentIdsDeletedElementsIT method assertElements.

@Override
protected void assertElements(final Iterable<ElementId> expected, final CloseableIterable<? extends EntityId> actual) {
    final List<ElementId> expectedIds = new ArrayList<>();
    for (final ElementId element : expected) {
        if (element instanceof EdgeId) {
            expectedIds.add(new EntitySeed(((EdgeId) element).getDestination()));
        }
    }
    super.assertElements(expectedIds, actual);
}
Also used : EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId)

Example 22 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeIdWithQueriedDestVertex.

@Test
public void shouldDeserialiseEdgeIdWithQueriedDestVertex() {
    // Given
    final EdgeId expectedElementId = new EdgeSeed("vertex1", "vertex2", true, EdgeId.MatchedVertex.DESTINATION);
    final Edge edge = new Edge.Builder().source("vertex1").dest("vertex2").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
    final Key key = converter.getKeysFromEdge(edge).getSecond();
    // 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 23 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeIdWithQueriedSourceVertex.

@Test
public void shouldDeserialiseEdgeIdWithQueriedSourceVertex() {
    // 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).getSecond();
    // 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 24 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class QueryGenerator method seedToPredicate.

private FilterPredicate seedToPredicate(final ParquetElementSeed seed, final SeededGraphFilters.IncludeIncomingOutgoingType includeIncomingOutgoingType, final SeedMatching.SeedMatchingType seedMatchingType, final String group, final boolean reversed) {
    final boolean isEntityGroup = schemaUtils.getEntityGroups().contains(group);
    FilterPredicate filter = null;
    final ElementId elementId = seed.getElementId();
    // Is it an entity group?
    if (isEntityGroup) {
        // EntityId case
        if (elementId instanceof EntityId) {
            filter = getIsEqualFilter(ParquetStore.VERTEX, ((ParquetEntitySeed) seed).getSeed(), group);
        } else {
            // EdgeId case
            // Does the seed type need to match the group type?
            final ParquetEdgeSeed edgeSeed = (ParquetEdgeSeed) seed;
            if (seedMatchingType != SeedMatching.SeedMatchingType.EQUAL) {
                // Vertex = source of edge seed or Vertex = destination of edge seed
                // look in partition 0 with filter src = A and partition 1 with filter src = B
                filter = getIsEqualFilter(ParquetStore.VERTEX, edgeSeed.getSource(), group);
                if (null != ((ParquetEdgeSeed) seed).getDestination()) {
                    filter = FilterPredicateUtils.or(filter, getIsEqualFilter(ParquetStore.VERTEX, edgeSeed.getDestination(), group));
                }
            }
        }
    } else {
        // EntityId case
        if (elementId instanceof EntityId) {
            // If seedMatchingType is EQUAL then we can't find anything in an edge group
            if (seedMatchingType != SeedMatching.SeedMatchingType.EQUAL) {
                if (includeIncomingOutgoingType == SeededGraphFilters.IncludeIncomingOutgoingType.INCOMING) {
                    if (reversed) {
                        // Dst is seed
                        filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
                    } else {
                        // Src is seed and edge is undirected
                        filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
                        filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
                    }
                } else if (includeIncomingOutgoingType == SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING) {
                    if (reversed) {
                        // Dst is seed and edge is undirected
                        filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
                        filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
                    } else {
                        // Src is seed
                        filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
                    }
                } else {
                    if (reversed) {
                        // Dst is seed
                        filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
                    } else {
                        // Src is seed
                        filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
                    }
                }
            }
        } else {
            // EdgeId case
            final ParquetEdgeSeed edgeSeed = (ParquetEdgeSeed) seed;
            if (!reversed) {
                // Src is source of edge seed and destination is destination of edge seed
                filter = getIsEqualFilter(ParquetStore.SOURCE, edgeSeed.getSource(), group);
                // WRONG seed is already serialised source and dest - now fixed?
                filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DESTINATION, edgeSeed.getDestination(), group));
                final DirectedType directedType = edgeSeed.getDirectedType();
                if (directedType == DirectedType.DIRECTED) {
                    filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { true }, group));
                } else if (directedType == DirectedType.UNDIRECTED) {
                    filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
                }
            } else {
                // TODO Optimise this - there are times this is unnecessary
                filter = getIsEqualFilter(ParquetStore.DESTINATION, edgeSeed.getSource(), group);
                filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.SOURCE, edgeSeed.getDestination(), group));
                final DirectedType directedType = edgeSeed.getDirectedType();
                if (directedType == DirectedType.DIRECTED) {
                    filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { true }, group));
                } else if (directedType == DirectedType.UNDIRECTED) {
                    filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
                }
            }
        }
    }
    LOGGER.debug("Returning {} from seedToPredicate", filter);
    return filter;
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId)

Example 25 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class GetElementsTest method shouldSetSeedMatchingTypeToEquals.

@Test
public void shouldSetSeedMatchingTypeToEquals() {
    // Given
    final ElementId elementId1 = new EntitySeed("identifier");
    // When
    final GetElements op = new GetElements.Builder().input(elementId1).seedMatching(SeedMatchingType.EQUAL).build();
    // Then
    assertEquals(SeedMatchingType.EQUAL, op.getSeedMatching());
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)58 Test (org.junit.jupiter.api.Test)32 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)29 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)17 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)14 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)14 HashSet (java.util.HashSet)11 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 User (uk.gov.gchq.gaffer.user.User)9 ArrayList (java.util.ArrayList)7 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)7 Test (org.junit.Test)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 Key (org.apache.accumulo.core.data.Key)4