Search in sources :

Example 96 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class GraphMutationsITCase method testRemoveEdges.

@Test
public void testRemoveEdges() throws Exception {
    /*
		 * Test removeEdges() -- simple case
		 */
    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<>(2L, 3L, 23L));
    // duplicate edge should be preserved in output
    graph = graph.addEdge(new Vertex<>(1L, 1L), new Vertex<>(2L, 2L), 12L);
    graph = graph.removeEdges(edgesToBeRemoved);
    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" + "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)

Example 97 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class GraphMutationsITCase method testAddExistingEdge.

@Test
public void testAddExistingEdge() throws Exception {
    /*
		 * Test addEdge() -- add already existing edge
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    graph = graph.addEdge(new Vertex<>(1L, 1L), new Vertex<>(2L, 2L), 12L);
    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" + "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 98 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment 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 99 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment in project flink by apache.

the class GraphMutationsITCase method testRemoveOneValidOneInvalidVertex.

@Test
public void testRemoveOneValidOneInvalidVertex() throws Exception {
    /*
		 * Test removeVertices() -- remove one invalid vertex and a valid one
		 */
    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<>(7L, 7L));
    graph = graph.removeVertices(verticesToBeRemoved);
    DataSet<Edge<Long, Long>> data = graph.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "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) ArrayList(java.util.ArrayList) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 100 with ExecutionEnvironment

use of org.apache.flink.api.java.ExecutionEnvironment 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

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1247 Test (org.junit.Test)1090 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)374 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)264 Plan (org.apache.flink.api.common.Plan)238 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)236 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)199 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)139 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)138 Vertex (org.apache.flink.graph.Vertex)93 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)73 Edge (org.apache.flink.graph.Edge)70 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)66 ArrayList (java.util.ArrayList)57 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)49 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)44 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)39 BatchTableEnvironment (org.apache.flink.table.api.java.BatchTableEnvironment)38 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)37 JobGraphGenerator (org.apache.flink.optimizer.plantranslate.JobGraphGenerator)35