Search in sources :

Example 6 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class BloomFilterIT method calculateRandomLookUpRate.

private double calculateRandomLookUpRate(final FileSKVIterator reader, final HashSet<Entity> dataSet, final Random random, final RangeFactory rangeFactory) throws IOException, AccumuloElementConversionException, RangeFactoryException {
    final EntitySeed[] randomData = new EntitySeed[5000];
    for (int i = 0; i < 5000; i++) {
        randomData[i] = new EntitySeed("type" + random.nextInt(Integer.MAX_VALUE));
    }
    final long start = System.currentTimeMillis();
    for (int i = 0; i < 5000; i++) {
        seek(reader, randomData[i], rangeFactory);
        if (dataSet.contains(randomData[i])) {
            assertTrue(reader.hasTop());
        }
    }
    final long end = System.currentTimeMillis();
    final double randomRate = 5000 / ((end - start) / 1000.0);
    LOGGER.info("Random look up rate = " + randomRate);
    return randomRate;
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 7 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class EntitySeedExtractorTest method shouldGetDestinationFromEdge.

@Test
public void shouldGetDestinationFromEdge() {
    // Given
    final EntitySeedExtractor extractor = new EntitySeedExtractor(IdentifierType.DESTINATION);
    final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", false);
    // When
    final EntitySeed seed = extractor.getObject(edge);
    // Then
    assertEquals("destination", seed.getVertex());
}
Also used : EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 8 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldStillApplyOtherFilter.

private void shouldStillApplyOtherFilter(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    // Query for all edges in set {A0, A23}
    final Set<EntitySeed> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
    // Set graph to give us edges only
    op.setIncludeEntities(false);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A0_A23));
    // Set graph to return entities only
    final GetElements<EntitySeed, ?> entitiesOnlyOp = new GetElements<>(defaultView, seeds);
    entitiesOnlyOp.setIncludeEntities(true);
    entitiesOnlyOp.setIncludeEdges(IncludeEdgeType.NONE);
    // Query for all edges in set {A0, A23}
    final Set<Element> entitiesOnlyResults = returnElementsFromOperation(store, entitiesOnlyOp, new User(), loadIntoMemory);
    assertThat(entitiesOnlyResults, IsCollectionContaining.hasItems(AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY));
    // Set graph to return both entities and edges again, and to only return summary type "X" (which will result
    // in no data)
    final View view = new View.Builder().edge("X").build();
    final GetElements<EntitySeed, ?> entitiesAndEdgesOp = new GetElements<>(view, seeds);
    entitiesAndEdgesOp.setIncludeEdges(IncludeEdgeType.ALL);
    entitiesAndEdgesOp.setIncludeEntities(true);
    final Set<Element> entitiesAndEdgesResults = returnElementsFromOperation(store, entitiesAndEdgesOp, new User(), loadIntoMemory);
    assertEquals(0, entitiesAndEdgesResults.size());
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 9 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.

private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    final Set<EntitySeed> seeds = new HashSet<>();
    seeds.add(new EntitySeed("C"));
    seeds.add(new EntitySeed("D"));
    final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
    // Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
    op.setIncludeEdges(GetOperation.IncludeEdgeType.UNDIRECTED);
    op.setIncludeEntities(false);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_UNDIRECTED));
    // Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
    final GetElements<EntitySeed, ?> directedCOop = new GetElements<>(defaultView, seeds);
    directedCOop.setIncludeEdges(IncludeEdgeType.DIRECTED);
    final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
    assertThat(directedCDResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_DIRECTED));
    final GetElements<EntitySeed, ?> bothDirectedAndUndirectedOp = new GetElements<>(defaultView, seeds);
    // Turn off directed / undirected edges only option and check get both the undirected and directed edge
    bothDirectedAndUndirectedOp.setIncludeEdges(IncludeEdgeType.ALL);
    final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
    assertThat(bothDirectedAndUndirectedResults, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_C_D_DIRECTED, ((Element) AccumuloTestData.EDGE_C_D_UNDIRECTED)));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet)

Example 10 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldGetCorrectEdges.

private void shouldGetCorrectEdges(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    // Query for all edges in set {A0, A23}
    final Set<EntitySeed> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY));
    // Query for all edges in set {A1} - there shouldn't be any, but we will get the entity for A1
    final GetElements<EntitySeed, ?> a1Operation = new GetElements<>(defaultView, AccumuloTestData.SEED_A1_SET);
    final Set<Element> a1Results = returnElementsFromOperation(store, a1Operation, new User(), loadIntoMemory);
    assertEquals(1, a1Results.size());
    assertThat(a1Results, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY));
    // Query for all edges in set {A1, A2} - there shouldn't be any edges but will
    // get the two entities
    final Set<EntitySeed> a1A2Seeds = new HashSet<>();
    a1A2Seeds.add(AccumuloTestData.SEED_A1);
    a1A2Seeds.add(AccumuloTestData.SEED_A2);
    final GetElements<EntitySeed, ?> a1A2Operation = new GetElements<>(defaultView, a1A2Seeds);
    final Set<Element> a1A2Results = returnElementsFromOperation(store, a1A2Operation, new User(), loadIntoMemory);
    assertEquals(2, a1A2Results.size());
    assertThat(a1A2Results, IsCollectionContaining.hasItems(AccumuloTestData.A1_ENTITY, AccumuloTestData.A2_ENTITY));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)107 Test (org.junit.Test)51 Element (uk.gov.gchq.gaffer.data.element.Element)50 User (uk.gov.gchq.gaffer.user.User)43 HashSet (java.util.HashSet)34 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)33 Entity (uk.gov.gchq.gaffer.data.element.Entity)28 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)28 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Edge (uk.gov.gchq.gaffer.data.element.Edge)22 Graph (uk.gov.gchq.gaffer.graph.Graph)22 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ArrayList (java.util.ArrayList)20 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)12 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)12 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)11 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)9