use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetJavaRDDOfElementsExample method getJavaRddOfElementsReturningEdgesOnly.
public void getJavaRddOfElementsReturningEdgesOnly(final JavaSparkContext sc, final Graph graph) throws OperationException {
ROOT_LOGGER.setLevel(Level.INFO);
log("#### get Java RDD of elements returning edges only\n");
printGraph();
ROOT_LOGGER.setLevel(Level.OFF);
final GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>().addSeed(new EdgeSeed(1, 2, true)).addSeed(new EdgeSeed(2, 3, true)).includeEntities(false).javaSparkContext(sc).build();
final JavaRDD<Element> rdd = graph.execute(operation, new User("user01"));
final List<Element> elements = rdd.collect();
ROOT_LOGGER.setLevel(Level.INFO);
printJava("GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>()\n" + " .addSeed(new EdgeSeed(1, 2, true))\n" + " .addSeed(new EdgeSeed(2, 3, true))\n" + " .includeEntities(false)\n" + " .javaSparkContext(sc)\n" + " .build();\n" + "JavaRDD<Element> rdd = graph.execute(operation, new User(\"user01\"));\n" + "List<Element> elements = rdd.collect();");
log("The results are:");
log("```");
for (final Element e : elements) {
log(e.toString());
}
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class AggregationIT method shouldGetAllElementsWithFilterSummarisation.
@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetAllElementsWithFilterSummarisation() throws Exception {
final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
edge1.putProperty(TestPropertyNames.INT, 100);
edge1.putProperty(TestPropertyNames.COUNT, 1L);
final Edge edge2 = edge1.emptyClone();
edge2.putProperty(TestPropertyNames.INT, 101);
edge2.putProperty(TestPropertyNames.COUNT, 1L);
graph.execute(new AddElements.Builder().elements(Arrays.asList((Element) edge1, edge2)).build(), getUser());
final GetAllElements<Element> op = new GetAllElements.Builder<>().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100, 101))).build()).build()).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
// aggregation is 'Max'
assertEquals(101, resultList.get(0).getProperty(TestPropertyNames.INT));
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class FilteringIT method testPostAggregationFilteringProperties.
@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
// Given
final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
// When - without filtering
final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
// When - with filtering
final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
// Then - without filtering
assertNotNull(resultsWithoutFiltering);
assertEquals(8, resultsWithoutFiltering.size());
assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
// Then - with filtering
assertNotNull(resultsWithFiltering);
assertEquals(6, resultsWithFiltering.size());
assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetAllElementsIT method shouldGetAllElementsWithFilterWithoutSummarisation.
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
@Test
public void shouldGetAllElementsWithFilterWithoutSummarisation() throws Exception {
final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
edge1.putProperty(TestPropertyNames.INT, 100);
edge1.putProperty(TestPropertyNames.COUNT, 1L);
final Edge edge2 = edge1.emptyClone();
edge2.putProperty(TestPropertyNames.INT, 101);
edge2.putProperty(TestPropertyNames.COUNT, 1L);
graph.execute(new AddElements.Builder().elements(Arrays.asList((Element) edge1, edge2)).build(), getUser());
final GetAllElements<Element> op = new GetAllElements.Builder<>().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100, 101))).build()).build()).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertEquals(2, resultList.size());
assertThat(resultList, IsCollectionContaining.hasItems((Element) edge1, edge2));
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetElementsIT method shouldGetRelatedElements.
private void shouldGetRelatedElements(boolean includeEntities, final IncludeEdgeType includeEdgeType, final IncludeIncomingOutgoingType inOutType) throws Exception {
final List<ElementSeed> seedTerms = new LinkedList<>();
final List<Element> expectedElements = new LinkedList<>();
if (includeEntities) {
for (final Object identifier : ALL_SEED_VERTICES) {
final EntitySeed entitySeed = new EntitySeed(identifier);
seedTerms.add(entitySeed);
}
}
if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.DIRECTED == includeEdgeType) {
final EdgeSeed seed = new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true);
seedTerms.add(seed);
if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.OUTGOING == inOutType) {
final EdgeSeed seedSourceDestDir2 = new EdgeSeed(SOURCE_DIR_2, DEST_DIR_2, true);
seedTerms.add(seedSourceDestDir2);
}
if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.INCOMING == inOutType) {
final EdgeSeed seedSourceDestDir3 = new EdgeSeed(SOURCE_DIR_3, DEST_DIR_3, true);
seedTerms.add(seedSourceDestDir3);
}
}
if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.UNDIRECTED == includeEdgeType) {
final EdgeSeed seedSourceDest1 = new EdgeSeed(SOURCE_1, DEST_1, false);
seedTerms.add(seedSourceDest1);
final EdgeSeed seedSourceDest2 = new EdgeSeed(SOURCE_2, DEST_2, false);
seedTerms.add(seedSourceDest2);
final EdgeSeed seedSourceDest3 = new EdgeSeed(SOURCE_3, DEST_3, false);
seedTerms.add(seedSourceDest3);
}
expectedElements.addAll(getElements(seedTerms));
shouldGetElements(expectedElements, SeedMatchingType.RELATED, includeEdgeType, includeEntities, inOutType, ALL_SEEDS);
}
Aggregations