use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.
the class LoadAndQuery11 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 DataGenerator11()).objects(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
log("Added an edge A-B 1000 times, each time with a DoublesUnion containing a normally distributed" + " (mean 0, standard deviation 1) random double.");
// [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 0.25, 0.5, 0.75 percentiles] Get the edge A-B and print an estimate of the 0.25, 0.5 and 0.75 quantiles, i.e. the 25th, 50th and 75th percentiles
// ---------------------------------------------------------
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 DoublesUnion doublesUnion = (DoublesUnion) edge.getProperty("doublesUnion");
final double[] quantiles = doublesUnion.getResult().getQuantiles(new double[] { 0.25D, 0.5D, 0.75D });
final String quantilesEstimate = "Edge A-B with percentiles of double property - 25th percentile: " + quantiles[0] + ", 50th percentile: " + quantiles[1] + ", 75th percentile: " + quantiles[2];
// ---------------------------------------------------------
log("\nEdge A-B with an estimate of the median value");
log("GET_0.25,0.5,0.75_PERCENTILES_FOR_EDGE_A_B", quantilesEstimate);
// [get cdf] Get the edge A-B and print some values from the cumulative density function
// ---------------------------------------------------------
final GetEdges<EdgeSeed> query2 = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
final Iterable<Edge> edges2 = graph.execute(query2, user);
final Edge edge2 = edges2.iterator().next();
final DoublesSketch doublesSketch2 = ((DoublesUnion) edge2.getProperty("doublesUnion")).getResult();
final double[] cdf = doublesSketch2.getCDF(new double[] { 0.0D, 1.0D, 2.0D });
final String cdfEstimate = "Edge A-B with CDF values at 0: " + cdf[0] + ", at 1: " + cdf[1] + ", at 2: " + cdf[2];
// ---------------------------------------------------------
log("\nEdge A-B with the cumulative density function values at 0, 1, 2");
log("GET_CDF_FOR_EDGE_A_B_RESULT", cdfEstimate);
return null;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges 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;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.
the class GetJobDetailsExample method getJobDetailsInOperationChain.
public JobDetail getJobDetailsInOperationChain() {
// ---------------------------------------------------------
final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new GetJobDetails()).build();
// ---------------------------------------------------------
final JobDetail jobDetail = runExample(opChain);
jobId = jobDetail.getJobId();
return jobDetail;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.
the class GetJobResultsExample method runExamples.
@Override
public void runExamples() {
try {
final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
final JobDetail jobDetails = getGraph().execute(opChain, new User("user01"));
jobId = jobDetails.getJobId();
} catch (final OperationException e) {
throw new RuntimeException(e);
}
getJobResults();
}
Aggregations