Search in sources :

Example 31 with Edge

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

the class GraphOperationsITCase method testFilterEdges.

@SuppressWarnings("serial")
@Test
public void testFilterEdges() throws Exception {
    /*
         * Test filterOnEdges:
         */
    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.filterOnEdges(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" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : 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 32 with Edge

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

the class GraphOperationsITCase method testDifference2.

@Test
public void testDifference2() throws Exception {
    /*
         * Test difference() such that no common vertices are there
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Vertex<Long, Long>> vertex = env.fromElements(new Vertex<>(6L, 6L));
    Graph<Long, Long, Long> graph2 = Graph.fromDataSet(vertex, TestGraphUtils.getLongLongEdgeDataDifference2(env), env);
    graph = graph.difference(graph2);
    List<Edge<Long, Long>> result = graph.getEdges().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) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 33 with Edge

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

the class GraphMutationsITCase method testRemoveEdge.

@Test
public void testRemoveEdge() throws Exception {
    /*
         * Test removeEdge() -- simple case
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    // duplicate edge should be preserved in output
    graph = graph.addEdge(new Vertex<>(1L, 1L), new Vertex<>(2L, 2L), 12L);
    graph = graph.removeEdge(new Edge<>(5L, 1L, 51L));
    DataSet<Edge<Long, Long>> data = graph.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,12\n" + "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "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) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 34 with Edge

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

the class GraphMutationsITCase method testRemoveSameEdgeTwice.

@Test
public void testRemoveSameEdgeTwice() throws Exception {
    /*
         * Test removeEdges() -- try to remove the same edge twice
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<>();
    edgesToBeRemoved.add(new Edge<>(5L, 1L, 51L));
    edgesToBeRemoved.add(new Edge<>(5L, 1L, 51L));
    graph = graph.removeEdges(edgesToBeRemoved);
    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";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 35 with Edge

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

the class GraphMutationsITCase method testRemoveVertices.

@Test
public void testRemoveVertices() throws Exception {
    /*
         * Test removeVertices() -- simple case
         */
    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<>(1L, 1L));
    verticesToBeRemoved.add(new Vertex<>(2L, 2L));
    graph = graph.removeVertices(verticesToBeRemoved);
    DataSet<Edge<Long, Long>> data = graph.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "3,4,34\n" + "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) 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