Search in sources :

Example 16 with EdgeSeed

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

the class AbstractCoreKeyRangeFactory method getRange.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge")
@Override
public <T extends GetElementsOperation<?, ?>> List<Range> getRange(final ElementSeed elementSeed, final T operation) throws RangeFactoryException {
    if (elementSeed instanceof EntitySeed) {
        if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching()) && !operation.isIncludeEntities()) {
            throw new IllegalArgumentException("When doing querying by ID, you should only provide an EntitySeed seed if you also set includeEntities flag to true");
        }
        return getRange(((EntitySeed) elementSeed).getVertex(), operation, operation.getIncludeEdges());
    } else {
        if (!operation.isIncludeEntities() && IncludeEdgeType.NONE == operation.getIncludeEdges()) {
            throw new IllegalArgumentException("Need to get either Entities and/or Edges when getting Elements");
        }
        final EdgeSeed edgeSeed = (EdgeSeed) elementSeed;
        final List<Range> ranges = new ArrayList<>();
        if (IncludeEdgeType.ALL == operation.getIncludeEdges() || (IncludeEdgeType.DIRECTED == operation.getIncludeEdges() && edgeSeed.isDirected()) || (IncludeEdgeType.UNDIRECTED == operation.getIncludeEdges() && !edgeSeed.isDirected())) {
            // Get Edges with the given EdgeSeed - This is applicable for
            // EQUALS and RELATED seed matching.
            ranges.add(new Range(getKeyFromEdgeSeed(edgeSeed, operation, false), true, getKeyFromEdgeSeed(edgeSeed, operation, true), true));
        }
        if (SeedMatchingType.RELATED.equals(operation.getSeedMatching()) && operation.isIncludeEntities()) {
            // Get Entities related to EdgeSeeds
            ranges.addAll(getRange(edgeSeed.getSource(), operation, IncludeEdgeType.NONE));
            ranges.addAll(getRange(edgeSeed.getDestination(), operation, IncludeEdgeType.NONE));
        }
        return ranges;
    }
}
Also used : EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with EdgeSeed

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

the class LoadAndQuery12 method run.

public Iterable<Entity> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator12()).objects(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    log("Added the edge A-B 1000 times each time with a ReservoirItemsUnion<String> containing a random string." + " Also added 500 edges X-Y0, X-Y1, ..., X-Y499 each and for each an Entity on X with a" + " ReservoirItemsUnion<String> containing the destination node.");
    // [get red edge] Get the red edge
    // ---------------------------------------------------------
    final GetAllEdges getAllEdges = new GetAllEdges.Builder().view(new View.Builder().edge("red").build()).build();
    final Iterable<Edge> allEdges = graph.execute(getAllEdges, user);
    // ---------------------------------------------------------
    log("\nThe red edge A-B:");
    for (final Edge edge : allEdges) {
        log("GET_A-B_EDGE_RESULT", edge.toString());
    }
    // [get strings sample from the red edge] Get the edge A-B and print out the sample of strings
    // ---------------------------------------------------------
    final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
    final Iterable<Edge> edges = graph.execute(query, user);
    final Edge edge = edges.iterator().next();
    final ReservoirItemsSketch<String> stringsSketch = ((ReservoirItemsUnion<String>) edge.getProperty("stringsSample")).getResult();
    final String[] samples = stringsSketch.getSamples();
    final StringBuilder sb = new StringBuilder("10 samples: ");
    for (int i = 0; i < 10 && i < samples.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        sb.append(samples[i]);
    }
    // ---------------------------------------------------------
    log("\nEdge A-B with a sample of the strings");
    log("GET_SAMPLE_FOR_RED_EDGE", sb.toString());
    // [get sample from the blue entity] Get the entity Y and print a sample of the neighbours
    // ---------------------------------------------------------
    final GetEntities<EntitySeed> query2 = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("X")).build();
    final Iterable<Entity> entities = graph.execute(query2, user);
    final Entity entity = entities.iterator().next();
    final ReservoirItemsSketch<String> neighboursSketch = ((ReservoirItemsUnion<String>) entity.getProperty("neighboursSample")).getResult();
    final String[] neighboursSample = neighboursSketch.getSamples();
    sb.setLength(0);
    sb.append("10 samples: ");
    for (int i = 0; i < 10 && i < neighboursSample.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        sb.append(neighboursSample[i]);
    }
    // ---------------------------------------------------------
    log("\nEntity for vertex X with a sample of its neighbouring vertices");
    log("GET_SAMPLES_FOR_X_RESULT", sb.toString());
    return null;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) DataGenerator12(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator12) Graph(uk.gov.gchq.gaffer.graph.Graph) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) ReservoirItemsUnion(com.yahoo.sketches.sampling.ReservoirItemsUnion)

Example 18 with EdgeSeed

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

the class ExportIT method createEdges.

/**
     * Adds edges dest[X] -> source[X+1]
     *
     * @return map of edges
     */
@Override
protected Map<EdgeSeed, Edge> createEdges() {
    final Map<EdgeSeed, Edge> edges = super.createEdges();
    for (int i = 0; i <= 10; i++) {
        final Edge thirdEdge = new Edge(TestGroups.EDGE, DEST_DIR + i, SOURCE_DIR + (i + 1), true);
        thirdEdge.putProperty(TestPropertyNames.INT, 1);
        thirdEdge.putProperty(TestPropertyNames.COUNT, 1L);
        addToMap(thirdEdge, edges);
    }
    return edges;
}
Also used : EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 19 with EdgeSeed

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

the class FilteringIT method testFilteringProperties.

@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() 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().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(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 20 with EdgeSeed

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

the class GeneratorsIT method shouldConvertFromDomainObjects.

@Test
public void shouldConvertFromDomainObjects() throws OperationException, UnsupportedEncodingException {
    // Given
    final OperationChain<Void> opChain = new OperationChain.Builder().first(new GenerateElements.Builder<DomainObject>().generator(new BasicGenerator()).objects(Arrays.asList(new EntityDomainObject(NEW_VERTEX, "1", null), new EdgeDomainObject(NEW_SOURCE, NEW_DEST, false, 1, 1L))).build()).then(new AddElements()).build();
    // When - add
    graph.execute(opChain, getUser());
    // Then - check they were added correctly
    final List<Element> results = Lists.newArrayList(graph.execute(new GetElements.Builder<>().addSeed(new EntitySeed(NEW_VERTEX)).addSeed(new EdgeSeed(NEW_SOURCE, NEW_DEST, false)).build(), getUser()));
    final Edge expectedEdge = new Edge(TestGroups.EDGE, NEW_SOURCE, NEW_DEST, false);
    expectedEdge.putProperty(TestPropertyNames.INT, 1);
    expectedEdge.putProperty(TestPropertyNames.COUNT, 1L);
    final Entity expectedEntity = new Entity(TestGroups.ENTITY, NEW_VERTEX);
    expectedEntity.putProperty(TestPropertyNames.STRING, "1");
    assertNotNull(results);
    assertEquals(2, results.size());
    assertThat(results, IsCollectionContaining.hasItems(expectedEntity, expectedEdge));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) BasicGenerator(uk.gov.gchq.gaffer.integration.generators.BasicGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Aggregations

EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)31 Edge (uk.gov.gchq.gaffer.data.element.Edge)16 Test (org.junit.Test)14 Element (uk.gov.gchq.gaffer.data.element.Element)12 User (uk.gov.gchq.gaffer.user.User)11 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)9 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)8 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)8 Graph (uk.gov.gchq.gaffer.graph.Graph)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)5 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 HashSet (java.util.HashSet)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3