Search in sources :

Example 91 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class LoadAndQuery15 method run.

public CloseableIterable<?> 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 DataGenerator15()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [job] create an operation chain to be executed as a job
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<Edge>> job = new OperationChain.Builder().first(new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build()).build();
    // ---------------------------------------------------------
    // [execute job] execute the job
    // ---------------------------------------------------------
    final JobDetail initialJobDetail = graph.executeJob(job, user);
    final String jobId = initialJobDetail.getJobId();
    // ---------------------------------------------------------
    log("JOB_DETAIL_START", initialJobDetail.toString());
    waitUntilJobHashFinished(user, graph, initialJobDetail);
    // [job details] Get the job details
    // ---------------------------------------------------------
    final JobDetail jobDetail = graph.execute(new GetJobDetails.Builder().jobId(jobId).build(), user);
    // ---------------------------------------------------------
    log("JOB_DETAIL_FINISH", jobDetail.toString());
    // [all job details] Get all job details
    // ---------------------------------------------------------
    final CloseableIterable<JobDetail> jobDetails = graph.execute(new GetAllJobDetails(), user);
    // ---------------------------------------------------------
    for (final JobDetail detail : jobDetails) {
        log("ALL_JOB_DETAILS", detail.toString());
    }
    // [get job results] Get the job results
    // ---------------------------------------------------------
    final CloseableIterable<?> jobResults = graph.execute(new GetJobResults.Builder().jobId(jobId).build(), user);
    // ---------------------------------------------------------
    for (final Object result : jobResults) {
        log("JOB_RESULTS", result.toString());
    }
    return jobResults;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) User(uk.gov.gchq.gaffer.user.User) DataGenerator15(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator15) GetJobResults(uk.gov.gchq.gaffer.operation.impl.job.GetJobResults) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 92 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements 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 93 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class OperationExample method createExampleGraph.

protected Graph createExampleGraph() {
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.openStreams(getClass(), "/example/operation/schema")).storeProperties(StreamUtil.openStream(getClass(), "/example/operation/mockaccumulostore.properties")).build();
    // Create data generator
    final DataGenerator dataGenerator = new DataGenerator();
    // Load data into memory
    final List<String> data = DataUtils.loadData(StreamUtil.openStream(getClass(), "/example/operation/data.txt", true));
    //add the edges to the graph using an operation chain consisting of:
    //generateElements - generating edges from the data (note these are directed edges)
    //addElements - add the edges to the graph
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(dataGenerator).objects(data).build()).then(new AddElements()).build();
    try {
        graph.execute(addOpChain, new User());
    } catch (OperationException e) {
        throw new RuntimeException(e);
    }
    return graph;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) DataGenerator(uk.gov.gchq.gaffer.example.operation.generator.DataGenerator) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 94 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class LoadAndQuery15Test method shouldReturnExpectedEdgesViaJson.

@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
    // Given
    final User user = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
    final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
    // Setup graph
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
    // When
    // Execute the add operation chain on the graph
    graph.execute(addElements, user);
    // Execute the query operation on the graph.
    final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
    // Then
    verifyResults(results);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 95 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class LoadAndQuery1Test method shouldReturnExpectedEdgesViaJson.

@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
    // Given
    final User user = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
    final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
    // Setup graph
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
    // When
    // Execute the add operation chain on the graph
    graph.execute(addElements, user);
    // Execute the query operation on the graph.
    final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
    // Then
    verifyResults(results);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)157 Graph (uk.gov.gchq.gaffer.graph.Graph)99 User (uk.gov.gchq.gaffer.user.User)98 Element (uk.gov.gchq.gaffer.data.element.Element)88 Test (org.junit.jupiter.api.Test)74 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)72 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)63 Edge (uk.gov.gchq.gaffer.data.element.Edge)62 Entity (uk.gov.gchq.gaffer.data.element.Entity)51 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)47 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)47 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)39 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)37 OperationException (uk.gov.gchq.gaffer.operation.OperationException)36 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)35 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)35 Test (org.junit.Test)30 Set (java.util.Set)28