Search in sources :

Example 36 with ElementSeed

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

the class GetElementsinRangesHandlerTest method shouldSummarise.

private void shouldSummarise(final AccumuloStore store) throws OperationException {
    // Create set to query for
    final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
    //get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
    simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("1")));
    final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
    final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
    final CloseableIterable<Element> elementsInRange = handler.doOperation(operation, user, store);
    int count = 0;
    for (final Element elm : elementsInRange) {
        //Make sure every element has been summarised
        assertEquals(9, elm.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
        count++;
    }
    assertEquals(1000, count);
    elementsInRange.close();
    simpleEntityRanges.clear();
    //This should get everything between 0 and 0799 (again being string ordering 0800 is more than 08)
    simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("08")));
    final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
    count = 0;
    for (final Element elm : elements) {
        //Make sure every element has been summarised
        assertEquals(9, elm.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
        count++;
    }
    assertEquals(800, count);
    elements.close();
}
Also used : GetElementsInRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges) Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) HashSet(java.util.HashSet) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 37 with ElementSeed

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

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEntitiesOnly.

private void testEntitySeedQueryEntitiesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEntities(true);
    operation.setIncludeEdges(IncludeEdgeType.NONE);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    //Should find only the entities i
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 38 with ElementSeed

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

the class AggregationIT method shouldAggregateIdenticalElements.

@Test
@TraitRequirement(StoreTrait.STORE_AGGREGATION)
public void shouldAggregateIdenticalElements() throws OperationException, UnsupportedEncodingException {
    // Given
    final GetElements<ElementSeed, Element> getElements = new GetElements.Builder<>().addSeed(new EntitySeed(AGGREGATED_SOURCE)).build();
    // When
    final List<Element> results = Lists.newArrayList(graph.execute(getElements, getUser()));
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    final Entity expectedEntity = new Entity(TestGroups.ENTITY, AGGREGATED_SOURCE);
    expectedEntity.putProperty(TestPropertyNames.STRING, "3,3");
    final Edge expectedEdge = new Edge(TestGroups.EDGE, AGGREGATED_SOURCE, AGGREGATED_DEST, false);
    expectedEdge.putProperty(TestPropertyNames.INT, 1);
    expectedEdge.putProperty(TestPropertyNames.COUNT, 2L);
    assertThat(results, IsCollectionContaining.hasItems(expectedEdge, expectedEntity));
    for (final Element result : results) {
        if (result instanceof Entity) {
            assertEquals(AGGREGATED_ID, result.getProperty(TestPropertyNames.STRING));
        } else {
            assertEquals(1, result.getProperty(TestPropertyNames.INT));
            assertEquals(2L, result.getProperty(TestPropertyNames.COUNT));
        }
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 39 with ElementSeed

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

the class FilteringIT method testPostAggregationFilteringProperties.

@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
    // Given
    final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
    final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
    final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
    // When - without filtering
    final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
    // When - with filtering
    final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
    // Then - without filtering
    assertNotNull(resultsWithoutFiltering);
    assertEquals(8, resultsWithoutFiltering.size());
    assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(6, resultsWithFiltering.size());
    assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.gaffer.function.filter.IsEqual) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 40 with ElementSeed

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

the class GetElementsIT method shouldGetRelatedElements.

private void shouldGetRelatedElements(boolean includeEntities, final IncludeEdgeType includeEdgeType, final IncludeIncomingOutgoingType inOutType) throws Exception {
    final List<ElementSeed> seedTerms = new LinkedList<>();
    final List<Element> expectedElements = new LinkedList<>();
    if (includeEntities) {
        for (final Object identifier : ALL_SEED_VERTICES) {
            final EntitySeed entitySeed = new EntitySeed(identifier);
            seedTerms.add(entitySeed);
        }
    }
    if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.DIRECTED == includeEdgeType) {
        final EdgeSeed seed = new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true);
        seedTerms.add(seed);
        if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.OUTGOING == inOutType) {
            final EdgeSeed seedSourceDestDir2 = new EdgeSeed(SOURCE_DIR_2, DEST_DIR_2, true);
            seedTerms.add(seedSourceDestDir2);
        }
        if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.INCOMING == inOutType) {
            final EdgeSeed seedSourceDestDir3 = new EdgeSeed(SOURCE_DIR_3, DEST_DIR_3, true);
            seedTerms.add(seedSourceDestDir3);
        }
    }
    if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.UNDIRECTED == includeEdgeType) {
        final EdgeSeed seedSourceDest1 = new EdgeSeed(SOURCE_1, DEST_1, false);
        seedTerms.add(seedSourceDest1);
        final EdgeSeed seedSourceDest2 = new EdgeSeed(SOURCE_2, DEST_2, false);
        seedTerms.add(seedSourceDest2);
        final EdgeSeed seedSourceDest3 = new EdgeSeed(SOURCE_3, DEST_3, false);
        seedTerms.add(seedSourceDest3);
    }
    expectedElements.addAll(getElements(seedTerms));
    shouldGetElements(expectedElements, SeedMatchingType.RELATED, includeEdgeType, includeEntities, inOutType, ALL_SEEDS);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) LinkedList(java.util.LinkedList)

Aggregations

ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)41 Element (uk.gov.gchq.gaffer.data.element.Element)26 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)26 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 HashSet (java.util.HashSet)13 User (uk.gov.gchq.gaffer.user.User)13 Test (org.junit.Test)12 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)12 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)9 Edge (uk.gov.gchq.gaffer.data.element.Edge)8 ArrayList (java.util.ArrayList)7 GetElementsInRanges (uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges)6 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)6 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 Range (org.apache.accumulo.core.data.Range)3 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)3 LinkedList (java.util.LinkedList)2 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2