Search in sources :

Example 6 with GraphFrameToIterableRow

use of uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow 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 GraphFrameToIterableRow

use of uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow 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 8 with GraphFrameToIterableRow

use of uk.gov.gchq.gaffer.spark.function.GraphFrameToIterableRow 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)8 Element (uk.gov.gchq.gaffer.data.element.Element)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 Graph (uk.gov.gchq.gaffer.graph.Graph)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 GetGraphFrameOfElements (uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements)8 User (uk.gov.gchq.gaffer.user.User)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 Entity (uk.gov.gchq.gaffer.data.element.Entity)1