use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class AccumuloRangeIDRetrieverTest method shouldRetieveElementsInRangeBetweenSeeds.
private void shouldRetieveElementsInRangeBetweenSeeds(final AccumuloStore store) throws StoreException {
// Create set to query for
final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0000"), new EntitySeed("0999")));
// Retrieve elements when less simple entities are provided than the max number of entries for the batch scanner
final GetElementsOperation<Pair<ElementSeed>, CloseableIterable<Element>> operation = new GetElementsInRanges<>(defaultView, simpleEntityRanges);
try {
final AccumuloRangeIDRetriever retriever = new AccumuloRangeIDRetriever(store, operation, new User());
assertEquals(numEntries, Iterables.size(retriever));
} catch (IteratorSettingException e) {
fail("Unable to construct Range Retriever");
}
}
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 GetAllElementsIT method shouldGetAllElements.
protected void shouldGetAllElements(boolean includeEntities, final IncludeEdgeType includeEdgeType) throws Exception {
// Given
final List<Element> expectedElements = new ArrayList<>();
if (includeEntities) {
expectedElements.addAll(getEntities().values());
}
for (final Edge edge : getEdges().values()) {
if (IncludeEdgeType.ALL == includeEdgeType || (edge.isDirected() && IncludeEdgeType.DIRECTED == includeEdgeType) || (!edge.isDirected() && IncludeEdgeType.UNDIRECTED == includeEdgeType)) {
expectedElements.add(edge);
}
}
final GetAllElements<Element> op = new GetAllElements.Builder<>().includeEntities(includeEntities).includeEdges(includeEdgeType).populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> expectedElementsCopy = Lists.newArrayList(expectedElements);
for (final Element result : results) {
final ElementSeed seed = ElementSeed.createSeed(result);
if (result instanceof Entity) {
Entity entity = (Entity) result;
assertTrue("Entity was not expected: " + entity, expectedElements.contains(entity));
} else {
Edge edge = (Edge) result;
if (edge.isDirected()) {
assertTrue("Edge was not expected: " + edge, expectedElements.contains(edge));
} else {
final Edge edgeReversed = new Edge(TestGroups.EDGE, edge.getDestination(), edge.getSource(), edge.isDirected());
expectedElementsCopy.remove(edgeReversed);
assertTrue("Edge was not expected: " + seed, expectedElements.contains(result) || expectedElements.contains(edgeReversed));
}
}
expectedElementsCopy.remove(result);
}
assertEquals("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy, expectedElements.size(), Lists.newArrayList(results).size());
}
Aggregations