Search in sources :

Example 1 with EPGMVertex

use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.

the class BuildIdPropertyValuePairsTest method testFunction.

/**
 * Test if the function selects the correct labels and properties.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testFunction() throws Exception {
    VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
    EPGMVertex v1 = vertexFactory.createVertex("a");
    EPGMVertex v2 = vertexFactory.createVertex("a");
    v2.setProperty("k1", 1L);
    v2.setProperty("k2", 1L);
    EPGMVertex v3 = vertexFactory.createVertex("b");
    v3.setProperty("k1", 1L);
    v3.setProperty("k2", 1L);
    EPGMVertex v4 = vertexFactory.createVertex();
    List<Tuple2<GradoopId, PropertyValue>> result = getExecutionEnvironment().fromElements(v1, v2, v3, v4).flatMap(new BuildIdPropertyValuePairs<>("a", "k1")).collect();
    assertEquals(1, result.size());
    assertEquals(Tuple2.of(v2.getId(), PropertyValue.create(1L)), result.get(0));
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 2 with EPGMVertex

use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.

the class CreateCartesianNeighborhoodEdgesTest method testWithEmptyNeighborhood.

/**
 * Test the function using an empty neighborhood. Should produce no edges.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testWithEmptyNeighborhood() throws Exception {
    EPGMVertex someVertex = vertexFactory.createVertex();
    Tuple2<EPGMVertex, List<NeighborhoodVertex>> inputEmpty = new Tuple2<>(someVertex, Collections.emptyList());
    List<EPGMEdge> result = getExecutionEnvironment().fromElements(inputEmpty).flatMap(toTest).collect();
    assertEquals(0, result.size());
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) List(java.util.List) Test(org.junit.Test)

Example 3 with EPGMVertex

use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.

the class CreateEdgesFromTripleTest method testFunction.

/**
 * Test the function by applying it to some tuples.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testFunction() throws Exception {
    CreateEdgesFromTriple<EPGMVertex, EPGMEdge> function = new CreateEdgesFromTriple<>(getConfig().getLogicalGraphFactory().getEdgeFactory(), "source", "target");
    VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
    EPGMVertex testVertex1 = vertexFactory.createVertex();
    EPGMVertex testVertex2 = vertexFactory.createVertex();
    GradoopId source1 = GradoopId.get();
    GradoopId source2 = GradoopId.get();
    GradoopId target1 = GradoopId.get();
    GradoopId target2 = GradoopId.get();
    Tuple3<EPGMVertex, GradoopId, GradoopId> tuple1 = new Tuple3<>(testVertex1, source1, target1);
    Tuple3<EPGMVertex, GradoopId, GradoopId> tuple2 = new Tuple3<>(testVertex2, source2, target2);
    List<EPGMEdge> result = getExecutionEnvironment().fromElements(tuple1, tuple2).flatMap(function).collect();
    // Check if the correct number of edges were created and if they are distinct.
    assertEquals(4, result.size());
    // By id.
    assertEquals(4, result.stream().map(EPGMElement::getId).count());
    // By source and target id.
    assertEquals(4, result.stream().map(e -> Tuple2.of(e.getSourceId(), e.getTargetId())).distinct().count());
    // Finally check the data of the edges.
    for (EPGMEdge resultEdge : result) {
        if (resultEdge.getLabel().equals("source")) {
            if (resultEdge.getSourceId().equals(source1)) {
                assertEquals(testVertex1.getId(), resultEdge.getTargetId());
            } else if (resultEdge.getSourceId().equals(source2)) {
                assertEquals(testVertex2.getId(), resultEdge.getTargetId());
            } else {
                fail("EPGMEdge with invalid source ID created.");
            }
        } else if (resultEdge.getLabel().equals("target")) {
            if (resultEdge.getSourceId().equals(testVertex1.getId())) {
                assertEquals(target1, resultEdge.getTargetId());
            } else if (resultEdge.getSourceId().equals(testVertex2.getId())) {
                assertEquals(target2, resultEdge.getTargetId());
            } else {
                fail("EPGMEdge with invalid source ID created.");
            }
        } else {
            fail("EPGMEdge with invalid label created.");
        }
    }
}
Also used : List(java.util.List) EPGMElement(org.gradoop.common.model.impl.pojo.EPGMElement) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Tuple2(org.apache.flink.api.java.tuple.Tuple2) VertexFactory(org.gradoop.common.model.api.entities.VertexFactory) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) GradoopFlinkTestBase(org.gradoop.flink.model.GradoopFlinkTestBase) Test(org.junit.Test) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Assert(org.junit.Assert) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) EPGMElement(org.gradoop.common.model.impl.pojo.EPGMElement) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) Tuple3(org.apache.flink.api.java.tuple.Tuple3) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Test(org.junit.Test)

Example 4 with EPGMVertex

use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.

the class CreateMappingFromMarkedDuplicatesTest method testFlatMapFunction.

/**
 * Test the flat map function.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testFlatMapFunction() throws Exception {
    VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
    GradoopId duplicateId = GradoopId.get();
    EPGMVertex vertexWithProp = vertexFactory.createVertex();
    vertexWithProp.setProperty(MarkDuplicatesInGroup.PROPERTY_KEY, PropertyValue.create(duplicateId));
    EPGMVertex vertexWithProp2 = vertexFactory.createVertex();
    vertexWithProp2.setProperty(MarkDuplicatesInGroup.PROPERTY_KEY, PropertyValue.create(duplicateId));
    EPGMVertex vertexWithoutProp = vertexFactory.createVertex();
    List<EPGMVertex> vertices = Arrays.asList(vertexWithoutProp, vertexWithProp, vertexWithProp2);
    vertices.sort(Comparator.comparing(EPGMElement::getId));
    List<Tuple2<GradoopId, GradoopId>> mapping = getExecutionEnvironment().fromCollection(vertices).flatMap(new CreateMappingFromMarkedDuplicates<>()).collect();
    assertEquals(2, mapping.size());
    assertNotEquals(mapping.get(0).f0, mapping.get(1).f0);
    assertEquals(duplicateId, mapping.get(0).f1);
    assertEquals(duplicateId, mapping.get(1).f1);
    assertNotEquals(vertexWithoutProp.getId(), mapping.get(0).f0);
    assertNotEquals(vertexWithoutProp.getId(), mapping.get(1).f0);
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Test(org.junit.Test)

Example 5 with EPGMVertex

use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.

the class MarkDuplicatesInGroupTest method testReduce.

/**
 * Test the reduce functionality.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testReduce() throws Exception {
    VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
    List<EPGMVertex> testVertices = IntStream.range(0, 10).mapToObj(i -> vertexFactory.createVertex()).collect(Collectors.toList());
    for (EPGMVertex testVertex : testVertices) {
        testVertex.setLabel("Test");
        testVertex.setProperty("a", PropertyValue.NULL_VALUE);
    }
    List<EPGMVertex> reduced = getExecutionEnvironment().fromCollection(testVertices).groupBy(new GetPropertiesAsList<>(Collections.singletonList("a"))).reduceGroup(new MarkDuplicatesInGroup<>()).collect();
    assertEquals(testVertices.size(), reduced.size());
    int numberOfMarkedElements = 0;
    GradoopId duplicateId = null;
    for (EPGMVertex vertex : reduced) {
        if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
            numberOfMarkedElements++;
        } else {
            assertNull("Duplicate ID was already found", duplicateId);
            duplicateId = vertex.getId();
        }
    }
    assertEquals(testVertices.size() - 1, numberOfMarkedElements);
    for (EPGMVertex vertex : reduced) {
        if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
            PropertyValue propertyValue = vertex.getPropertyValue(MarkDuplicatesInGroup.PROPERTY_KEY);
            assertTrue(propertyValue.isGradoopId());
            assertEquals(duplicateId, propertyValue.getGradoopId());
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) VertexFactory(org.gradoop.common.model.api.entities.VertexFactory) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) GradoopFlinkTestBase(org.gradoop.flink.model.GradoopFlinkTestBase) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Collections(java.util.Collections) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Assert.assertEquals(org.junit.Assert.assertEquals) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Test(org.junit.Test)

Aggregations

EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)209 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)137 EPGMGraphHead (org.gradoop.common.model.impl.pojo.EPGMGraphHead)91 Test (org.junit.Test)90 LogicalGraph (org.gradoop.flink.model.impl.epgm.LogicalGraph)53 Test (org.testng.annotations.Test)44 FlinkAsciiGraphLoader (org.gradoop.flink.util.FlinkAsciiGraphLoader)39 GradoopId (org.gradoop.common.model.impl.id.GradoopId)36 GraphCollection (org.gradoop.flink.model.impl.epgm.GraphCollection)30 ArrayList (java.util.ArrayList)28 GradoopIdSet (org.gradoop.common.model.impl.id.GradoopIdSet)24 List (java.util.List)23 PropertyValue (org.gradoop.common.model.impl.properties.PropertyValue)22 Properties (org.gradoop.common.model.impl.properties.Properties)21 Collectors (java.util.stream.Collectors)18 EPGMVertexFactory (org.gradoop.common.model.impl.pojo.EPGMVertexFactory)17 CNF (org.gradoop.flink.model.impl.operators.matching.common.query.predicates.CNF)16 Embedding (org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding)16 HBaseEPGMStore (org.gradoop.storage.hbase.impl.HBaseEPGMStore)16 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)15