use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities in project Gaffer by gchq.
the class AccumuloAggregationIT method shouldHandleAggregatationWhenNoAggregatorsAreProvided.
@Test
public void shouldHandleAggregatationWhenNoAggregatorsAreProvided() throws OperationException, UnsupportedEncodingException {
final Graph graph = createGraphNoAggregators();
final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity entity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity entity5 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").build();
final Entity entity6 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").build();
final Entity entity7 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
// Duplicate the entities to check they are not aggregated
graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
// Given
final GetAllEntities getAllEntities = new GetAllEntities();
// When
final List<Entity> results = Lists.newArrayList(graph.execute(getAllEntities, USER));
// Then
assertNotNull(results);
assertEquals(14, results.size());
final Entity expectedEntity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity expectedEntity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity expectedEntity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
final Entity expectedEntity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
assertThat(results, IsCollectionContaining.hasItems(expectedEntity1, expectedEntity2, expectedEntity3, expectedEntity4));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities in project Gaffer by gchq.
the class ExamplesService method getAllEntities.
@Override
public GetAllEntities getAllEntities() {
final GetAllEntities op = new GetAllEntities();
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities in project Gaffer by gchq.
the class LoadAndQuery9Test method shouldReturnExpectedEdgesViaJson.
@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
// Given
final User user = new User("user01");
final JSONSerialiser serialiser = new JSONSerialiser();
final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
final GetAllEntities getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetAllEntities.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, user);
// Execute the query operation on the graph.
final Iterable<Entity> results = graph.execute(getRelatedEdges, user);
// Then
verifyResults(results);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities in project Gaffer by gchq.
the class LoadAndQuery13 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 DataGenerator13()).objects(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
log("Added 1000 edges A-B0, A-B1, ..., A-B999 on 10/1/17. For each edge we create an Entity with a union sketch" + " containing a string of the source and destination from the edge. Added 500 edges A-B750, A-B751, " + "..., A-B1249 for day 11/1/17. Again for each edge we create an Entity with a union sketch.");
// [get entities] Get the entities for separate days
// ---------------------------------------------------------
final GetAllEntities get = new GetAllEntities();
final Iterable<Entity> entities = graph.execute(get, user);
for (final Entity entity : entities) {
log("GET_ENTITIES", entity.toString());
}
// ---------------------------------------------------------
// [get estimate separate days] Get the estimates out of the sketches for the separate days
// ---------------------------------------------------------
final GetAllEntities getAllEntities2 = new GetAllEntities();
final Iterable<Entity> allEntities2 = graph.execute(getAllEntities2, user);
final Iterator<Entity> it = allEntities2.iterator();
final Entity entityDay1 = it.next();
final CompactSketch sketchDay1 = ((Union) entityDay1.getProperty("size")).getResult();
final Entity entityDay2 = it.next();
final CompactSketch sketchDay2 = ((Union) entityDay2.getProperty("size")).getResult();
final double estimateDay1 = sketchDay1.getEstimate();
final double estimateDay2 = sketchDay2.getEstimate();
// ---------------------------------------------------------
log("\nThe estimates for the different days");
log("GET_ESTIMATE_OVER_SEPARATE_DAYS", "" + estimateDay1);
log("GET_ESTIMATE_OVER_SEPARATE_DAYS", "" + estimateDay2);
// [get intersection] Get the number of edges in common across the two days
// ---------------------------------------------------------
final Intersection intersection = Sketches.setOperationBuilder().buildIntersection();
intersection.update(sketchDay1);
intersection.update(sketchDay2);
final double intersectionSizeEstimate = intersection.getResult().getEstimate();
// ---------------------------------------------------------
log("\nThe estimate of the number of edges in common across the different days");
log("PRINT_ESTIMATE", "" + intersectionSizeEstimate);
// [get union across all days] Get the total number edges across the two days
// ---------------------------------------------------------
final GetAllEntities getAllEntities = new GetAllEntities.Builder().view(new View.Builder().entity("size", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
final Iterable<Entity> allEntities = graph.execute(getAllEntities, user);
final Entity entity = allEntities.iterator().next();
final double unionSizeEstimate = ((Union) entity.getProperty("size")).getResult().getEstimate();
// ---------------------------------------------------------
log("\nThe estimate of the number of edges across the different days");
log("UNION_ESTIMATE", "" + unionSizeEstimate);
return null;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities 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;
}
Aggregations