use of uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements in project Gaffer by gchq.
the class RowToElementGeneratorTest method checkGetCorrectElementsInGraphFrame.
@Test
public void checkGetCorrectElementsInGraphFrame() throws OperationException {
// Given
final Graph graph = getGraph("/schema-GraphFrame/elements.json", getElements());
final GetGraphFrameOfElements gfOperation = new GetGraphFrameOfElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build()).build();
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(gfOperation).then(new Map.Builder<>().first(new GraphFrameToIterableRow()).build()).then(new GenerateElements.Builder<Row>().generator(new RowToElementGenerator()).build()).build();
// When
final Iterable<? extends Element> result = graph.execute(opChain, new User());
// Then
ElementUtil.assertElementEquals(getElements(), result);
}
use of uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements in project Gaffer by gchq.
the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithNoElements.
@Test
public void shouldGetCorrectElementsInGraphFrameWithNoElements() throws OperationException {
// Given
final Graph graph = getGraph("/schema-GraphFrame/elements.json", new ArrayList<>());
final GetGraphFrameOfElements gfOperation = new GetGraphFrameOfElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).edge(TestGroups.EDGE_2).entity(TestGroups.ENTITY).entity(TestGroups.ENTITY_2).build()).build();
// When
final GraphFrame graphFrame = graph.execute(gfOperation, new User());
// Then
assertTrue(graphFrame.edges().javaRDD().isEmpty());
assertTrue(graphFrame.vertices().javaRDD().isEmpty());
}
use of uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements in project Gaffer by gchq.
the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithNoEdges.
@Test
public void shouldGetCorrectElementsInGraphFrameWithNoEdges() throws OperationException {
// Given
final Graph graph = getGraph("/schema-GraphFrame/elements.json", getSimpleElements());
final GetGraphFrameOfElements gfOperation = new GetGraphFrameOfElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).entity(TestGroups.ENTITY_2).build()).build();
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(gfOperation).then(new Map.Builder<>().first(new GraphFrameToIterableRow()).then(new RowToElementGenerator()).build()).build();
// When
final Iterable<? extends Element> results = graph.execute(opChain, new User());
// Then
assertElementEquals(getSimpleElements().stream().filter(e -> e instanceof Entity).collect(Collectors.toList()), results);
}
use of uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements in project Gaffer by gchq.
the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithMultipleEdgesBetweenVertices.
@Test
public void shouldGetCorrectElementsInGraphFrameWithMultipleEdgesBetweenVertices() throws OperationException {
// Given
final Graph graph = getGraph("/schema-GraphFrame/elementsComplex.json", getElements());
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE_2).source("1").dest("B").directed(true).property("columnQualifier", 1).property("property1", 2).property("property2", 3.0F).property("property3", 4.0D).property("property4", 5L).property("count", 100L).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE_2).source("1").dest("C").directed(true).property("columnQualifier", 6).property("property1", 7).property("property2", 8.0F).property("property3", 9.0D).property("property4", 10L).property("count", 200L).build();
graph.execute(new AddElements.Builder().input(edge1, edge2).build(), new User());
final GetGraphFrameOfElements gfOperation = new GetGraphFrameOfElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).edge(TestGroups.EDGE_2).entity(TestGroups.ENTITY).entity(TestGroups.ENTITY_2).build()).build();
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(gfOperation).then(new Map.Builder<>().first(new GraphFrameToIterableRow()).then(new RowToElementGenerator()).build()).build();
// When
final Iterable<? extends Element> results = graph.execute(opChain, new User());
// Then
final List<Element> expected = getElements();
expected.add(edge1);
expected.add(edge2);
assertElementEquals(expected, results);
}
Aggregations