Search in sources :

Example 21 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GatherSumApplyConfigurationITCase method testIterationDirectionALL.

@Test
public void testIterationDirectionALL() throws Exception {
    /*
         * Test that if the direction parameter OUT is given, the iteration works as expected
         * (i.e. it gathers information from both IN and OUT edges and neighbors
         * When data is gathered from the ALL edges the Gather Sum and Apply functions
         * set the set of vertices which are connected to a Vertex through some path as value of that vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.setDirection(EdgeDirection.ALL);
    List<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdges();
    edges.remove(0);
    Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), edges, env).mapVertices(new GatherSumApplyConfigurationITCase.InitialiseHashSetMapper());
    DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runGatherSumApplyIteration(new GetReachableVertices(), new FindAllReachableVertices(), new UpdateReachableVertices(), 4, parameters).getVertices();
    List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
    expectedResult = "1,[1, 2, 3, 4, 5]\n" + "2,[1, 2, 3, 4, 5]\n" + "3,[1, 2, 3, 4, 5]\n" + "4,[1, 2, 3, 4, 5]\n" + "5,[1, 2, 3, 4, 5]\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration) Edge(org.apache.flink.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GraphOperationsITCase method testSubGraph.

@SuppressWarnings("serial")
@Test
public void testSubGraph() throws Exception {
    /*
         * Test subgraph:
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Edge<Long, Long>> data = graph.subgraph(new FilterFunction<Vertex<Long, Long>>() {

        public boolean filter(Vertex<Long, Long> vertex) throws Exception {
            return (vertex.getValue() > 2);
        }
    }, new FilterFunction<Edge<Long, Long>>() {

        public boolean filter(Edge<Long, Long> edge) throws Exception {
            return (edge.getValue() > 34);
        }
    }).getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "3,5,35\n" + "4,5,45\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) FilterFunction(org.apache.flink.api.common.functions.FilterFunction) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 23 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GraphOperationsITCase method testDifference.

@Test
public void testDifference() throws Exception {
    /*Test  difference() method  by checking    the output  for getEdges()   on  the resultant   graph
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> graph2 = Graph.fromDataSet(TestGraphUtils.getLongLongVertexDataDifference(env), TestGraphUtils.getLongLongEdgeDataDifference(env), env);
    graph = graph.difference(graph2);
    List<Edge<Long, Long>> result = graph.getEdges().collect();
    expectedResult = "4,5,45\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 24 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GraphOperationsITCase method testIntersect.

@Test
public final void testIntersect() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
    edges1.add(new Edge<>(1L, 3L, 12L));
    // needs to be in the output
    edges1.add(new Edge<>(1L, 3L, 13L));
    edges1.add(new Edge<>(1L, 3L, 14L));
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
    edges2.add(new Edge<>(1L, 3L, 13L));
    Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env);
    Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env);
    Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true);
    List<Vertex<Long, NullValue>> vertices = new ArrayList<>();
    List<Edge<Long, Long>> edges = new ArrayList<>();
    intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices));
    intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges));
    env.execute();
    String expectedVertices = "1,(null)\n" + "3,(null)\n";
    String expectedEdges = "1,3,13\n";
    compareResultAsTuples(vertices, expectedVertices);
    compareResultAsTuples(edges, expectedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) NullValue(org.apache.flink.types.NullValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 25 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GraphMutationsITCase method testRemoveBothInvalidVertices.

@Test
public void testRemoveBothInvalidVertices() throws Exception {
    /*
         * Test removeVertices() -- remove two invalid vertices
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<>();
    verticesToBeRemoved.add(new Vertex<>(6L, 6L));
    verticesToBeRemoved.add(new Vertex<>(7L, 7L));
    graph = graph.removeVertices(verticesToBeRemoved);
    DataSet<Edge<Long, Long>> data = graph.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)87 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)72 Test (org.junit.Test)69 Vertex (org.apache.flink.graph.Vertex)46 NullValue (org.apache.flink.types.NullValue)20 LongValue (org.apache.flink.types.LongValue)16 ArrayList (java.util.ArrayList)14 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)12 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)7 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)7 Plan (org.apache.flink.api.common.Plan)6 FieldList (org.apache.flink.api.common.operators.util.FieldList)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)6 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)6 PlanNode (org.apache.flink.optimizer.plan.PlanNode)6 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)6 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)6 LinkedList (java.util.LinkedList)5 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)5