Search in sources :

Example 6 with GetGraphFrameOfElements

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);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GraphFrameToIterableRow(uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) RowToElementGenerator(uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 7 with GetGraphFrameOfElements

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) GraphFrame(org.graphframes.GraphFrame) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 8 with GetGraphFrameOfElements

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GraphFrameToIterableRow(uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) RowToElementGenerator(uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 9 with GetGraphFrameOfElements

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GraphFrameToIterableRow(uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) RowToElementGenerator(uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Edge(uk.gov.gchq.gaffer.data.element.Edge) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)9 Graph (uk.gov.gchq.gaffer.graph.Graph)9 GetGraphFrameOfElements (uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements)9 User (uk.gov.gchq.gaffer.user.User)9 Element (uk.gov.gchq.gaffer.data.element.Element)8 Map (uk.gov.gchq.gaffer.operation.impl.Map)8 RowToElementGenerator (uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator)8 GraphFrameToIterableRow (uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)3 GraphFrame (org.graphframes.GraphFrame)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1