Search in sources :

Example 6 with GetEntities

use of uk.gov.gchq.gaffer.operation.impl.get.GetEntities in project Gaffer by gchq.

the class ExamplesService method getRelatedEntities.

@Override
public GetEntities getRelatedEntities() {
    final GetEntities op = new GetEntities();
    final List<ElementSeed> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntitySeed(1));
    }
    if (hasEdges()) {
        seeds.add(getEdgeSeed(1, 2));
    }
    op.setSeeds(seeds);
    populateOperation(op);
    return op;
}
Also used : ArrayList(java.util.ArrayList) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities)

Example 7 with GetEntities

use of uk.gov.gchq.gaffer.operation.impl.get.GetEntities in project Gaffer by gchq.

the class LoadAndQuery9 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 OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator9()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Get all edges
    // ---------------------------------------------------------
    final Iterable<Edge> edges = graph.execute(new GetAllEdges(), user);
    // ---------------------------------------------------------
    log("\nAll edges:");
    for (final Edge edge : edges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get all cardinalities] Get all cardinalities
    // ---------------------------------------------------------
    final GetAllEntities getAllCardinalities = new GetAllEntities.Builder().view(new View.Builder().entity("Cardinality").build()).build();
    // ---------------------------------------------------------
    final CloseableIterable<Entity> allCardinalities = graph.execute(getAllCardinalities, user);
    log("\nAll cardinalities");
    for (final Entity cardinality : allCardinalities) {
        final String edgeGroup = (cardinality.getProperty("edgeGroup")).toString();
        log("ALL_CARDINALITIES_RESULT", "Vertex " + cardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) cardinality.getProperty("hllp")).cardinality());
    }
    // [get all summarised cardinalities] Get all summarised cardinalities over all edges
    // ---------------------------------------------------------
    final GetAllEntities getAllSummarisedCardinalities = new GetAllEntities.Builder().view(new View.Builder().entity("Cardinality", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
    // ---------------------------------------------------------
    final CloseableIterable<Entity> allSummarisedCardinalities = graph.execute(getAllSummarisedCardinalities, user);
    log("\nAll summarised cardinalities");
    for (final Entity cardinality : allSummarisedCardinalities) {
        final String edgeGroup = (cardinality.getProperty("edgeGroup")).toString();
        log("ALL_SUMMARISED_CARDINALITIES_RESULT", "Vertex " + cardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) cardinality.getProperty("hllp")).cardinality());
    }
    // [get red edge cardinality 1] Get the cardinality value at vertex 1 for red edges
    // ---------------------------------------------------------
    final GetEntities<EntitySeed> getCardinalities = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(new View.Builder().entity("Cardinality", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("edgeGroup").execute(new IsEqual(CollectionUtil.treeSet("red"))).build()).build()).build()).build();
    // ---------------------------------------------------------
    final Entity redCardinality = graph.execute(getCardinalities, user).iterator().next();
    // ---------------------------------------------------------
    log("\nRed edge cardinality at vertex 1:");
    final String edgeGroup = (redCardinality.getProperty("edgeGroup")).toString();
    log("CARDINALITY_OF_1_RESULT", "Vertex " + redCardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) redCardinality.getProperty("hllp")).cardinality());
    return allSummarisedCardinalities;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) GetAllEntities(uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities) User(uk.gov.gchq.gaffer.user.User) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) IsEqual(uk.gov.gchq.gaffer.function.filter.IsEqual) DataGenerator9(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator9) Graph(uk.gov.gchq.gaffer.graph.Graph) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 8 with GetEntities

use of uk.gov.gchq.gaffer.operation.impl.get.GetEntities in project Gaffer by gchq.

the class ExamplesService method getEntities.

@Override
public GetEntities getEntities() {
    final GetEntities op = new GetEntities();
    final List<ElementSeed> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntitySeed(1));
    }
    if (hasEdges()) {
        seeds.add(getEdgeSeed(1, 2));
    }
    op.setSeeds(seeds);
    populateOperation(op);
    return op;
}
Also used : ArrayList(java.util.ArrayList) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities)

Example 9 with GetEntities

use of uk.gov.gchq.gaffer.operation.impl.get.GetEntities in project Gaffer by gchq.

the class ExamplesService method getEntitiesBySeed.

@Override
public GetEntities getEntitiesBySeed() {
    final GetEntities op = new GetEntities<>();
    if (hasEntities()) {
        op.setSeeds(Collections.singletonList(getEntitySeed(1)));
    }
    populateOperation(op);
    return op;
}
Also used : GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities)

Example 10 with GetEntities

use of uk.gov.gchq.gaffer.operation.impl.get.GetEntities in project Gaffer by gchq.

the class TransformationIT method shouldTransformExistingProperty.

@Test
@TraitRequirement(StoreTrait.TRANSFORMATION)
public void shouldTransformExistingProperty() throws OperationException {
    // Given
    final GetEntities<EntitySeed> getEntities = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("A1")).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(IdentifierType.VERTEX.name(), TestPropertyNames.STRING).execute(new Concat()).project(TestPropertyNames.STRING).build()).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getEntities, getUser()));
    assertNotNull(results);
    assertEquals(1, results.size());
    for (final Entity result : results) {
        assertEquals("A1,3", result.getProperty(TestPropertyNames.STRING));
    }
}
Also used : Concat(uk.gov.gchq.gaffer.function.transform.Concat) Entity(uk.gov.gchq.gaffer.data.element.Entity) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)14 Test (org.junit.Test)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)9 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)8 Graph (uk.gov.gchq.gaffer.graph.Graph)7 Builder (uk.gov.gchq.gaffer.graph.Graph.Builder)6 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 ArrayList (java.util.ArrayList)2 Concat (uk.gov.gchq.gaffer.function.transform.Concat)2 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)2 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)2 User (uk.gov.gchq.gaffer.user.User)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1 ExpectedException (org.junit.rules.ExpectedException)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 DataGenerator9 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator9)1