Search in sources :

Example 6 with GetAllEdges

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

the class LoadAndQuery8 method run.

public Iterable<Edge> run() throws OperationException {
    // [user] Create a user who can see public and private data
    // ---------------------------------------------------------
    final User user = new User.Builder().userId("user").dataAuths("public", "private").build();
    // ---------------------------------------------------------
    // [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 DataGenerator8()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Get all edges
    // ---------------------------------------------------------
    final GetAllEdges allEdgesOperation = new GetAllEdges();
    final Iterable<Edge> edges = graph.execute(allEdgesOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges in daily time buckets:");
    for (final Edge edge : edges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get all edges summarised] Get all edges summarised (merge all time windows together)
    // This is achieved by overriding the 'groupBy' start and end time properties.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarised = graph.execute(edgesSummarisedOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges summarised:");
    for (final Edge edge : edgesSummarised) {
        log("GET_ALL_EDGES_SUMMARISED_RESULT", edge.toString());
    }
    // [get all edges summarised in time window] Get all edges summarised over a provided 2 day time period
    // This is achieved by overriding the 'groupBy' start and end time properties
    // and providing a filter.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedInTimeWindowOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_16, true)).select("endDate").execute(new IsLessThan(JAN_02_16, true)).build()).groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, user);
    // ---------------------------------------------------------
    log("\nEdges in 2 day time window:");
    for (final Edge edge : edgesSummarisedInTimeWindow) {
        log("GET_ALL_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    // Repeat with a public user and you will see the private edges are not part of the summarised edges
    final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
    final Iterable<Edge> publicEdgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, publicUser);
    log("\nPublic edges in 2 day time window:");
    for (final Edge edge : publicEdgesSummarisedInTimeWindow) {
        log("GET_PUBLIC_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    return publicEdgesSummarisedInTimeWindow;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) DataGenerator8(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator8) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 7 with GetAllEdges

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

the class ExportToGafferResultCacheExample method exportAndGetJobDetails.

public JobDetail exportAndGetJobDetails() {
    // ---------------------------------------------------------
    final OperationChain<JobDetail> exportOpChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
    // ---------------------------------------------------------
    jobDetail = runExample(exportOpChain);
    return jobDetail;
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)

Example 8 with GetAllEdges

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

the class GetGafferResultCacheExportExample method exportAndGetJobDetails.

public JobDetail exportAndGetJobDetails() {
    // ---------------------------------------------------------
    final OperationChain<JobDetail> exportOpChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
    // ---------------------------------------------------------
    jobDetail = runExample(exportOpChain);
    return jobDetail;
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)

Example 9 with GetAllEdges

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

the class LoadAndQuery8Test method shouldReturnExpectedStringsViaJson.

@Test
public void shouldReturnExpectedStringsViaJson() throws OperationException, SerialisationException {
    // Given
    final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
    final JSONSerialiser serialiser = new JSONSerialiser();
    final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
    final GetAllEdges getAllEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetAllEdges.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(addOpChain, publicUser);
    // Execute the query operation on the graph.
    final Iterable<Edge> results = graph.execute(getAllEdges, publicUser);
    // Then
    verifyResults(results);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 10 with GetAllEdges

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

the class LoadAndQuery10 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 DataGenerator10()).objects(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    log("Added an edge A-B 1000 times, each time with a LongsSketch containing a random long between 0 and 9.");
    // [get] Get all edges
    // ---------------------------------------------------------
    Iterable<Edge> allEdges = graph.execute(new GetAllEdges(), user);
    // ---------------------------------------------------------
    log("\nAll edges:");
    for (final Edge edge : allEdges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get frequencies of 1L and 9L] Get the edge A-B and print estimates of frequencies of 1L and 9L
    // ---------------------------------------------------------
    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 LongsSketch longsSketch = (LongsSketch) edge.getProperty("longsSketch");
    final String estimates = "Edge A-B: 1L seen approximately " + longsSketch.getEstimate(1L) + " times, 9L seen approximately " + longsSketch.getEstimate(9L) + " times.";
    // ---------------------------------------------------------
    log("\nEdge A-B with estimates of the frequencies of 1 and 9");
    log("GET_FREQUENCIES_OF_1_AND_9_FOR_EDGE_A_B", estimates);
    return null;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) DataGenerator10(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator10) User(uk.gov.gchq.gaffer.user.User) LongsSketch(com.yahoo.sketches.frequencies.LongsSketch) 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) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Aggregations

GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)14 User (uk.gov.gchq.gaffer.user.User)10 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)9 Edge (uk.gov.gchq.gaffer.data.element.Edge)6 Graph (uk.gov.gchq.gaffer.graph.Graph)6 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)5 Test (org.junit.Test)4 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)3 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1 LongsSketch (com.yahoo.sketches.frequencies.LongsSketch)1 DoublesSketch (com.yahoo.sketches.quantiles.DoublesSketch)1 DoublesUnion (com.yahoo.sketches.quantiles.DoublesUnion)1 ReservoirItemsUnion (com.yahoo.sketches.sampling.ReservoirItemsUnion)1 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1