Search in sources :

Example 1 with RowToElementGenerator

use of uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator in project Gaffer by gchq.

the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithRepeatedElements.

@Test
public void shouldGetCorrectElementsInGraphFrameWithRepeatedElements() throws OperationException {
    // Given
    final Graph graph = getGraph("/schema-GraphFrame/elements.json", getSimpleElements());
    graph.execute(new AddElements.Builder().input(getSimpleElements()).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
    assertElementEquals(getSimpleElements(), 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) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 2 with RowToElementGenerator

use of uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator in project Gaffer by gchq.

the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithLoops.

@Test
public void shouldGetCorrectElementsInGraphFrameWithLoops() throws OperationException {
    // Given
    final Graph graph = getGraph("/schema-GraphFrame/elementsComplex.json", getElements());
    final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("B").dest("1").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).source("C").dest("1").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)

Example 3 with RowToElementGenerator

use of uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator in project Gaffer by gchq.

the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrameWithVertexProperty.

@Test
public void shouldGetCorrectElementsInGraphFrameWithVertexProperty() throws OperationException {
    // Given
    final List<Element> elements = getSimpleElements();
    for (final Element element : elements) {
        element.putProperty("vertex", "value");
    }
    final Graph graph = getGraph("/schema-GraphFrame/elementsWithVertexProperty.json", elements);
    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
    assertElementEquals(getSimpleElements(), results);
}
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) 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 4 with RowToElementGenerator

use of uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator in project Gaffer by gchq.

the class GetGraphFrameOfElementsHandlerTest method shouldBehaviourInGraphFrameWithNoEntities.

@Test
public void shouldBehaviourInGraphFrameWithNoEntities() throws OperationException {
    // Given
    final Graph graph = getGraph("/schema-GraphFrame/elements.json", getSimpleElements());
    final GetGraphFrameOfElements gfOperation = new GetGraphFrameOfElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).edge(TestGroups.EDGE_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 Edge).collect(Collectors.toList()), results);
}
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) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetGraphFrameOfElements(uk.gov.gchq.gaffer.spark.operation.graphframe.GetGraphFrameOfElements) Map(uk.gov.gchq.gaffer.operation.impl.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 5 with RowToElementGenerator

use of uk.gov.gchq.gaffer.spark.data.generator.RowToElementGenerator in project Gaffer by gchq.

the class GetGraphFrameOfElementsHandlerTest method shouldGetCorrectElementsInGraphFrame.

@Test
public void shouldGetCorrectElementsInGraphFrame() throws OperationException {
    // Given
    final Graph graph = getGraph("/schema-GraphFrame/elements.json", getSimpleElements());
    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
    assertElementEquals(getSimpleElements(), results);
}
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) 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)

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