use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class AbstractGetOperationTest method shouldSerialiseAndDeserialiseOperation.
@Test
@Override
public void shouldSerialiseAndDeserialiseOperation() throws SerialisationException {
// Given
final String identifier = "identifier";
final ElementSeed input = new EntitySeed(identifier);
final GetOperationImpl<ElementSeed, Element> op = new GetOperationImpl<>(Collections.singletonList(input));
// When
byte[] json = serialiser.serialise(op, true);
final GetOperationImpl<ElementSeed, Element> deserialisedOp = serialiser.deserialise(json, GetOperationImpl.class);
// Then
assertNotNull(deserialisedOp);
assertEquals(identifier, ((EntitySeed) deserialisedOp.getInput().iterator().next()).getVertex());
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class GetJavaRDDOfElementsExample method getJavaRddOfElements.
public void getJavaRddOfElements(final JavaSparkContext sc, final Graph graph) throws OperationException {
ROOT_LOGGER.setLevel(Level.INFO);
// Avoid using getMethodNameAsSentence as it messes up the formatting of the "RDD" part
log("#### get Java RDD of elements\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)).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" + " .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.ElementSeed in project Gaffer by gchq.
the class ExamplesService method getRelatedEdges.
@Override
public GetEdges getRelatedEdges() {
final GetEdges op = new GetEdges();
final List<ElementSeed> seeds = new ArrayList<>();
if (hasEntities()) {
seeds.add(getEntitySeed(1));
} else if (hasEdges()) {
seeds.add(new EntitySeed(getEdgeSeed(1, 2).getSource()));
}
if (hasEdges()) {
seeds.add(getEdgeSeed(1, 2));
}
op.setSeeds(seeds);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class ExamplesService method getRelatedEntities.
@Override
public GetEntities getRelatedEntities() {
final GetEntities op = new GetEntities();
final List<ElementSeed> seeds = new ArrayList<>();
if (hasEntities()) {
seeds.add(getEntitySeed(1));
}
if (hasEdges()) {
seeds.add(getEdgeSeed(1, 2));
}
op.setSeeds(seeds);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class FilteringIT method testFilteringProperties.
@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() 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().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(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")));
}
Aggregations