Search in sources :

Example 66 with Edge

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

the class MapEdgesITCase method testWithStringValue.

@Test
public void testWithStringValue() throws Exception {
    /*
		 * Test mapEdges() and change the value type to String
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Edge<Long, String>> mappedEdges = graph.mapEdges(new ToStringMapper()).getEdges();
    List<Edge<Long, String>> result = mappedEdges.collect();
    expectedResult = "1,2,string(12)\n" + "1,3,string(13)\n" + "2,3,string(23)\n" + "3,4,string(34)\n" + "3,5,string(35)\n" + "4,5,string(45)\n" + "5,1,string(51)\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 67 with Edge

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

the class GraphOperationsITCase method testUnion.

@Test
public void testUnion() throws Exception {
    /*
		 * Test union()
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    List<Vertex<Long, Long>> vertices = new ArrayList<>();
    List<Edge<Long, Long>> edges = new ArrayList<>();
    vertices.add(new Vertex<>(6L, 6L));
    edges.add(new Edge<>(6L, 1L, 61L));
    graph = graph.union(Graph.fromCollection(vertices, edges, env));
    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" + "6,1,61\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)

Example 68 with Edge

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

the class GraphOperationsITCase method testIntersectWithPairs.

@Test
public final void testIntersectWithPairs() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
    edges1.add(new Edge<>(1L, 3L, 12L));
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 14L));
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
    // output
    edges2.add(new Edge<>(1L, 3L, 13L));
    // output
    edges2.add(new Edge<>(1L, 3L, 13L));
    // output
    edges2.add(new Edge<>(1L, 3L, 14L));
    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, false);
    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" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14";
    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 69 with Edge

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

the class GraphOperationsITCase method testReverse.

@Test
public void testReverse() throws Exception {
    /*
		 * Test reverse()
		 */
    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.reverse().getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "2,1,12\n" + "3,1,13\n" + "3,2,23\n" + "4,3,34\n" + "5,3,35\n" + "5,4,45\n" + "1,5,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 70 with Edge

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

the class GraphOperationsITCase method testFilterVertices.

@SuppressWarnings("serial")
@Test
public void testFilterVertices() throws Exception {
    /*
		 * Test filterOnVertices:
		 */
    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.filterOnVertices(new FilterFunction<Vertex<Long, Long>>() {

        public boolean filter(Vertex<Long, Long> vertex) throws Exception {
            return (vertex.getValue() > 2);
        }
    }).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) FilterFunction(org.apache.flink.api.common.functions.FilterFunction) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)82 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)70 Test (org.junit.Test)66 Vertex (org.apache.flink.graph.Vertex)39 NullValue (org.apache.flink.types.NullValue)18 ArrayList (java.util.ArrayList)14 LongValue (org.apache.flink.types.LongValue)13 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)11 MapFunction (org.apache.flink.api.common.functions.MapFunction)6 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)6 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)6 LinkedList (java.util.LinkedList)5 Plan (org.apache.flink.api.common.Plan)5 FieldList (org.apache.flink.api.common.operators.util.FieldList)5 DataSet (org.apache.flink.api.java.DataSet)5 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)5 Graph (org.apache.flink.graph.Graph)5 Tuple2ToVertexMap (org.apache.flink.graph.utils.Tuple2ToVertexMap)5 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)5 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)5