Search in sources :

Example 71 with Edge

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

the class JoinWithEdgesITCase method testWithEdgesInputDataset.

@Test
public void testWithEdgesInputDataset() throws Exception {
    /*
		 * Test joinWithEdges with the input DataSet parameter identical
		 * to the edge DataSet
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdges(graph.getEdges().map(new EdgeToTuple3Map<Long, Long>()), new AddValuesMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,46\n" + "3,4,68\n" + "3,5,70\n" + "4,5,90\n" + "5,1,102\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) EdgeToTuple3Map(org.apache.flink.graph.utils.EdgeToTuple3Map) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 72 with Edge

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

the class JoinWithEdgesITCase method testWithNoCommonKeys.

@Test
public void testWithNoCommonKeys() throws Exception {
    /*
		 * Test joinWithEdges with the input DataSet containing different keys than the edge DataSet
		 * - the iterator becomes empty.
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdges(TestGraphUtils.getLongLongLongTuple3Data(env), new DoubleValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,46\n" + "3,4,68\n" + "3,5,35\n" + "4,5,45\n" + "5,1,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 73 with Edge

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

the class JoinWithEdgesITCase method testOnSourceWithCustom.

@Test
public void testOnSourceWithCustom() throws Exception {
    /*
	     * Test joinWithEdgesOnSource with a DataSet containing custom parametrised type input values
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdgesOnSource(TestGraphUtils.getLongCustomTuple2SourceData(env), new CustomValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,10\n" + "1,3,10\n" + "2,3,30\n" + "3,4,40\n" + "3,5,40\n" + "4,5,45\n" + "5,1,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 74 with Edge

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

the class GraphMutationsITCase method testRemoveInvalidEdge.

@Test
public void testRemoveInvalidEdge() throws Exception {
    /*
		 * Test removeEdge() -- invalid edge
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    graph = graph.removeEdge(new Edge<>(6L, 1L, 61L));
    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 : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 75 with Edge

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

the class GraphMutationsITCase method testAddEdgesInvalidVertices.

@Test
public void testAddEdgesInvalidVertices() throws Exception {
    /*
		 * Test addEdges() -- the source and target vertices do not exist in the graph
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    List<Edge<Long, Long>> edgesToBeAdded = new ArrayList<>();
    edgesToBeAdded.add(new Edge<>(6L, 1L, 61L));
    edgesToBeAdded.add(new Edge<>(7L, 1L, 71L));
    graph = graph.addEdges(edgesToBeAdded);
    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 : 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)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