You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by va...@apache.org on 2015/05/26 22:44:16 UTC
[2/3] flink git commit: [FLINK-2012] [gelly] Changed addVertices to
operate on vertices only
[FLINK-2012] [gelly] Changed addVertices to operate on vertices only
This closes #678
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/bc19aa38
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/bc19aa38
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/bc19aa38
Branch: refs/heads/master
Commit: bc19aa3880bfcb7005f1900d2d00d35c53d777aa
Parents: edcfd8b
Author: andralungu <lu...@gmail.com>
Authored: Mon May 25 19:29:24 2015 +0200
Committer: vasia <va...@apache.org>
Committed: Tue May 26 22:43:26 2015 +0200
----------------------------------------------------------------------
docs/libs/gelly_guide.md | 20 +-
.../main/java/org/apache/flink/graph/Graph.java | 143 +++++------
.../test/operations/GraphMutationsITCase.java | 245 ++++++++-----------
3 files changed, 172 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/bc19aa38/docs/libs/gelly_guide.md
----------------------------------------------------------------------
diff --git a/docs/libs/gelly_guide.md b/docs/libs/gelly_guide.md
index 19d442a..87466d2 100644
--- a/docs/libs/gelly_guide.md
+++ b/docs/libs/gelly_guide.md
@@ -248,29 +248,29 @@ Graph Mutations
Gelly includes the following methods for adding and removing vertices and edges from an input `Graph`:
{% highlight java %}
-// adds a Vertex and the given edges to the Graph. If the Vertex already exists, it will not be added again, but the given edges will.
-Graph<K, VV, EV> addVertex(final Vertex<K, VV> vertex, List<Edge<K, EV>> edges)
+// adds a Vertex to the Graph. If the Vertex already exists, it will not be added again.
+Graph<K, VV, EV> addVertex(final Vertex<K, VV> vertex)
-// adds a data set of vertices and a list of edges to the Graph. If the vertices already exist in the graph, they will not be added once more, however the edges will.
-Graph<K, VV, EV> addVertices(DataSet<Vertex<K, VV>> verticesToAdd, List<Edge<K, EV>> edges)
+// adds a list of vertices to the Graph. If the vertices already exist in the graph, they will not be added once more.
+Graph<K, VV, EV> addVertices(List<Vertex<K, VV>> verticesToAdd)
// adds an Edge to the Graph. If the source and target vertices do not exist in the graph, they will also be added.
Graph<K, VV, EV> addEdge(Vertex<K, VV> source, Vertex<K, VV> target, EV edgeValue)
-// adds a data set of edges to the Graph. If the vertices already exist in the graph, they will not be added, however the edges will.
-Graph<K, VV, EV> addEdges(DataSet<Edge<K, EV>> newEdges, DataSet<Vertex<K, VV>> newVertices)
+// adds a list of edges to the Graph. When adding an edge for a non-existing set of vertices, the edge is considered invalid and ignored.
+Graph<K, VV, EV> addEdges(List<Edge<K, EV>> newEdges)
// removes the given Vertex and its edges from the Graph.
Graph<K, VV, EV> removeVertex(Vertex<K, VV> vertex)
-// removes the given data set of Vertices and their edges from the Graph
-Graph<K, VV, EV> removeVertices(DataSet<Vertex<K, VV>> verticesToBeRemoved)
+// removes the given list of vertices and their edges from the Graph
+Graph<K, VV, EV> removeVertices(List<Vertex<K, VV>> verticesToBeRemoved)
// removes *all* edges that match the given Edge from the Graph.
Graph<K, VV, EV> removeEdge(Edge<K, EV> edge)
-// removes *all* edges that match the edges in the given data set
-Graph<K, VV, EV> removeEdges(DataSet<Edge<K, EV>> edgesToBeRemoved)
+// removes *all* edges that match the edges in the given list
+Graph<K, VV, EV> removeEdges(List<Edge<K, EV>> edgesToBeRemoved)
{% endhighlight %}
Neighborhood Methods
http://git-wip-us.apache.org/repos/asf/flink/blob/bc19aa38/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/Graph.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/Graph.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/Graph.java
index 151450d..dab1a8f 100755
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/Graph.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/Graph.java
@@ -18,6 +18,7 @@
package org.apache.flink.graph;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -1005,46 +1006,33 @@ public class Graph<K, VV, EV> {
}
/**
- * Adds the input vertex and edges to the graph. If the vertex already
- * exists in the graph, it will not be added again, but the given edges
- * will.
+ * Adds the input vertex to the graph. If the vertex already
+ * exists in the graph, it will not be added again.
*
- * @param vertex the vertex to add to the graph
- * @param edges a list of edges to add to the graph
- * @return the new graph containing the existing and newly added vertex
- * and edges
+ * @param vertex the vertex to be added
+ * @return the new graph containing the existing vertices as well as the one just added
*/
@SuppressWarnings("unchecked")
- public Graph<K, VV, EV> addVertex(final Vertex<K, VV> vertex, List<Edge<K, EV>> edges) {
- DataSet<Vertex<K, VV>> newVertex = this.context.fromElements(vertex);
+ public Graph<K, VV, EV> addVertex(final Vertex<K, VV> vertex) {
+ List<Vertex<K, VV>> newVertex = new ArrayList<Vertex<K, VV>>();
+ newVertex.add(vertex);
- return addVertices(newVertex, edges);
+ return addVertices(newVertex);
}
/**
- * Adds the data set of vertices and the edges, passed as input, to the graph.
- * If the vertices already exist in the graph, they will not be added once more,
- * however the edges will.
+ * Adds the list of vertices, passed as input, to the graph.
+ * If the vertices already exist in the graph, they will not be added once more.
*
- * @param verticesToAdd the data set of vertices to add
- * @param edges a list of edges to add to the graph
+ * @param verticesToAdd the list of vertices to add
* @return the new graph containing the existing and newly added vertices
- * and edges
*/
@SuppressWarnings("unchecked")
- public Graph<K, VV, EV> addVertices(DataSet<Vertex<K, VV>> verticesToAdd, List<Edge<K, EV>> edges) {
+ public Graph<K, VV, EV> addVertices(List<Vertex<K, VV>> verticesToAdd) {
+ // Add the vertices
+ DataSet<Vertex<K, VV>> newVertices = this.vertices.union(this.context.fromCollection(verticesToAdd)).distinct();
- // Consider empty edge set
- if (edges.isEmpty()) {
- return new Graph<K, VV, EV>(this.vertices.union(verticesToAdd)
- .distinct(), this.edges, this.context);
- }
-
- // Add the vertex and its edges
- DataSet<Vertex<K, VV>> newVertices = this.vertices.union(verticesToAdd).distinct();
- DataSet<Edge<K, EV>> newEdges = this.edges.union(context.fromCollection(edges));
-
- return new Graph<K, VV, EV>(newVertices, newEdges, this.context);
+ return new Graph<K, VV, EV>(newVertices, this.edges, this.context);
}
/**
@@ -1066,83 +1054,72 @@ public class Graph<K, VV, EV> {
}
/**
- * Adds the given data set of edges to the graph. if the vertices do not already exist in the
- * graph, they will also be added.
+ * Adds the given list edges to the graph.
*
- * If the vertex values are not required during the computation, it is recommended to use
- * addEdges(edges)
+ * When adding an edge for a non-existing set of vertices, the edge is considered invalid and ignored.
*
* @param newEdges the data set of edges to be added
- * @param newVertices their corresponding vertices and vertexValues
- * @return a new graph containing the existing vertices and edges plus the newly added edges and vertices.
+ * @return a new graph containing the existing edges plus the newly added edges.
*/
@SuppressWarnings("unchecked")
- public Graph<K, VV, EV> addEdges(DataSet<Edge<K, EV>> newEdges, DataSet<Vertex<K, VV>> newVertices) {
- Graph<K, VV, EV> partialGraph = fromDataSet(newVertices, newEdges, context);
- return this.union(partialGraph);
- }
+ public Graph<K, VV, EV> addEdges(List<Edge<K, EV>> newEdges) {
- /**
- * Removes the given vertex and its edges from the graph.
- *
- * @param vertex the vertex to remove
- * @return the new graph containing the existing vertices and edges without
- * the removed vertex and its edges
- */
- public Graph<K, VV, EV> removeVertex(Vertex<K, VV> vertex) {
-
- DataSet<Vertex<K, VV>> newVertices = getVertices().filter(new RemoveVertexFilter<K, VV>(vertex));
- DataSet<Edge<K, EV>> newEdges = getEdges().filter(new VertexRemovalEdgeFilter<K, VV, EV>(vertex));
- return new Graph<K, VV, EV>(newVertices, newEdges, this.context);
- }
+ DataSet<Edge<K,EV>> newEdgesDataSet = this.context.fromCollection(newEdges);
- private static final class RemoveVertexFilter<K, VV>
- implements FilterFunction<Vertex<K, VV>> {
+ DataSet<Edge<K,EV>> validNewEdges = this.getVertices().join(newEdgesDataSet)
+ .where(0).equalTo(0)
+ .with(new JoinVerticesWithEdgesOnSrc<K, VV, EV>())
+ .join(this.getVertices()).where(1).equalTo(0)
+ .with(new JoinWithVerticesOnTrg<K, VV, EV>());
- private Vertex<K, VV> vertexToRemove;
+ return Graph.fromDataSet(this.vertices, this.edges.union(validNewEdges), this.context);
+ }
- public RemoveVertexFilter(Vertex<K, VV> vertex) {
- vertexToRemove = vertex;
- }
+ @ForwardedFieldsSecond("f0; f1; f2")
+ private static final class JoinVerticesWithEdgesOnSrc<K, VV, EV> implements
+ JoinFunction<Vertex<K, VV>, Edge<K, EV>, Edge<K, EV>> {
@Override
- public boolean filter(Vertex<K, VV> vertex) throws Exception {
- return !vertex.f0.equals(vertexToRemove.f0);
+ public Edge<K, EV> join(Vertex<K, VV> vertex, Edge<K, EV> edge) throws Exception {
+ return edge;
}
}
- private static final class VertexRemovalEdgeFilter<K, VV, EV>
- implements FilterFunction<Edge<K, EV>> {
-
- private Vertex<K, VV> vertexToRemove;
+ @ForwardedFieldsFirst("f0; f1; f2")
+ private static final class JoinWithVerticesOnTrg<K, VV, EV> implements
+ JoinFunction<Edge<K, EV>, Vertex<K, VV>, Edge<K, EV>> {
- public VertexRemovalEdgeFilter(Vertex<K, VV> vertex) {
- vertexToRemove = vertex;
+ @Override
+ public Edge<K, EV> join(Edge<K, EV> edge, Vertex<K, VV> vertex) throws Exception {
+ return edge;
}
+ }
- @Override
- public boolean filter(Edge<K, EV> edge) throws Exception {
+ /**
+ * Removes the given vertex and its edges from the graph.
+ *
+ * @param vertex the vertex to remove
+ * @return the new graph containing the existing vertices and edges without
+ * the removed vertex and its edges
+ */
+ public Graph<K, VV, EV> removeVertex(Vertex<K, VV> vertex) {
- if (edge.f0.equals(vertexToRemove.f0)) {
- return false;
- }
- if (edge.f1.equals(vertexToRemove.f0)) {
- return false;
- }
- return true;
- }
+ List<Vertex<K, VV>> vertexToBeRemoved = new ArrayList<Vertex<K, VV>>();
+ vertexToBeRemoved.add(vertex);
+
+ return removeVertices(vertexToBeRemoved);
}
/**
- * Removes the given data set of vertices and its edges from the graph.
+ * Removes the given list of vertices and its edges from the graph.
*
- * @param verticesToBeRemoved the data set of vertices to be removed
+ * @param verticesToBeRemoved the list of vertices to be removed
* @return the resulted graph containing the initial vertices and edges minus the vertices
* and edges removed.
*/
- public Graph<K, VV, EV> removeVertices(DataSet<Vertex<K, VV>> verticesToBeRemoved) {
+ public Graph<K, VV, EV> removeVertices(List<Vertex<K, VV>> verticesToBeRemoved) {
- DataSet<Vertex<K, VV>> newVertices = getVertices().coGroup(verticesToBeRemoved).where(0).equalTo(0)
+ DataSet<Vertex<K, VV>> newVertices = getVertices().coGroup(this.context.fromCollection(verticesToBeRemoved)).where(0).equalTo(0)
.with(new VerticesRemovalCoGroup<K, VV>());
DataSet < Edge < K, EV >> newEdges = newVertices.join(getEdges()).where(0).equalTo(0)
@@ -1212,13 +1189,13 @@ public class Graph<K, VV, EV> {
/**
* Removes all the edges that match the edges in the given data set from the graph.
*
- * @param edgesToBeRemoved the data set of edges to be removed
+ * @param edgesToBeRemoved the list of edges to be removed
* @return a new graph where the edges have been removed and in which the vertices remained intact
*/
- public Graph<K, VV, EV> removeEdges(DataSet<Edge<K, EV>> edgesToBeRemoved) {
+ public Graph<K, VV, EV> removeEdges(List<Edge<K, EV>> edgesToBeRemoved) {
- DataSet<Edge<K, EV>> newEdges = getEdges().coGroup(edgesToBeRemoved).where(0,1).equalTo(0,1)
- .with(new EdgeRemovalCoGroup<K, EV>());
+ DataSet<Edge<K, EV>> newEdges = getEdges().coGroup(this.context.fromCollection(edgesToBeRemoved))
+ .where(0,1).equalTo(0,1).with(new EdgeRemovalCoGroup<K, EV>());
return new Graph<K, VV, EV>(this.vertices, newEdges, context);
}
http://git-wip-us.apache.org/repos/asf/flink/blob/bc19aa38/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/GraphMutationsITCase.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/GraphMutationsITCase.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/GraphMutationsITCase.java
index 6aa4ef3..0d71b97 100644
--- a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/GraphMutationsITCase.java
+++ b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/GraphMutationsITCase.java
@@ -21,14 +21,12 @@ package org.apache.flink.graph.test.operations;
import java.util.ArrayList;
import java.util.List;
-import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.graph.Edge;
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.test.TestGraphUtils;
import org.apache.flink.test.util.MultipleProgramsTestBase;
-import org.apache.flink.types.NullValue;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -71,20 +69,16 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- edges.add(new Edge<Long, Long>(6L, 1L, 61L));
- graph = graph.addVertex(new Vertex<Long, Long>(6L, 6L), edges);
- graph.getEdges().writeAsCsv(resultPath);
+ graph = graph.addVertex(new Vertex<Long, Long>(6L, 6L));
+ graph.getVertices().writeAsCsv(resultPath);
env.execute();
- 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";
+ expectedResult = "1,1\n" +
+ "2,2\n" +
+ "3,3\n" +
+ "4,4\n" +
+ "5,5\n" +
+ "6,6\n";
}
@Test
@@ -98,26 +92,22 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- edges.add(new Edge<Long, Long>(6L, 1L, 61L));
- edges.add(new Edge<Long, Long>(7L, 1L, 71L));
+ List<Vertex<Long, Long>> vertices = new ArrayList<Vertex<Long, Long>>();
+ vertices.add(new Vertex<Long, Long>(6L, 6L));
+ vertices.add(new Vertex<Long, Long>(7L, 7L));
- DataSet<Vertex<Long, Long>> newVertices = env.fromElements(new Vertex<Long, Long>(6L, 6L),
- new Vertex<Long, Long>(7L, 7L));
- graph = graph.addVertices(newVertices, edges);
+ graph = graph.addVertices(vertices);
- graph.getEdges().writeAsCsv(resultPath);
+ graph.getVertices().writeAsCsv(resultPath);
env.execute();
- 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" +
- "7,1,71\n";
+ expectedResult = "1,1\n" +
+ "2,2\n" +
+ "3,3\n" +
+ "4,4\n" +
+ "5,5\n" +
+ "6,6\n" +
+ "7,7\n";
}
@Test
@@ -126,24 +116,19 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
* Test addVertex() -- add an existing vertex
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-
+
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
-
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- edges.add(new Edge<Long, Long>(1L, 5L, 15L));
- graph = graph.addVertex(new Vertex<Long, Long>(1L, 1L), edges);
- graph.getEdges().writeAsCsv(resultPath);
+
+ graph = graph.addVertex(new Vertex<Long, Long>(1L, 1L));
+ graph.getVertices().writeAsCsv(resultPath);
env.execute();
- expectedResult = "1,2,12\n" +
- "1,3,13\n" +
- "1,5,15\n" +
- "2,3,23\n" +
- "3,4,34\n" +
- "3,5,35\n" +
- "4,5,45\n" +
- "5,1,51\n";
+ expectedResult = "1,1\n" +
+ "2,2\n" +
+ "3,3\n" +
+ "4,4\n" +
+ "5,5\n";
}
@Test
@@ -157,26 +142,20 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- edges.add(new Edge<Long, Long>(1L, 5L, 15L));
- edges.add(new Edge<Long, Long>(3L, 1L, 31L));
+ List<Vertex<Long, Long>> vertices = new ArrayList<Vertex<Long, Long>>();
+ vertices.add(new Vertex<Long, Long>(1L, 1L));
+ vertices.add(new Vertex<Long, Long>(3L, 3L));
- DataSet<Vertex<Long, Long>> newVertices = env.fromElements(new Vertex<Long, Long>(1L, 1L),
- new Vertex<Long, Long>(3L, 3L));
- graph = graph.addVertices(newVertices, edges);
+ graph = graph.addVertices(vertices);
- graph.getEdges().writeAsCsv(resultPath);
+ graph.getVertices().writeAsCsv(resultPath);
env.execute();
- expectedResult = "1,2,12\n" +
- "1,3,13\n" +
- "1,5,15\n" +
- "2,3,23\n" +
- "3,4,34\n" +
- "3,5,35\n" +
- "3,1,31\n" +
- "4,5,45\n" +
- "5,1,51\n";
+ expectedResult = "1,1\n" +
+ "2,2\n" +
+ "3,3\n" +
+ "4,4\n" +
+ "5,5\n";
}
@Test
@@ -190,66 +169,11 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- edges.add(new Edge<Long, Long>(1L, 5L, 15L));
- edges.add(new Edge<Long, Long>(6L, 1L, 61L));
+ List<Vertex<Long, Long>> vertices = new ArrayList<Vertex<Long, Long>>();
+ vertices.add(new Vertex<Long, Long>(1L, 1L));
+ vertices.add(new Vertex<Long, Long>(6L, 6L));
- DataSet<Vertex<Long, Long>> newVertices = env.fromElements(new Vertex<Long, Long>(1L, 1L),
- new Vertex<Long, Long>(6L, 6L));
- graph = graph.addVertices(newVertices, edges);
-
- graph.getEdges().writeAsCsv(resultPath);
- env.execute();
-
- expectedResult = "1,2,12\n" +
- "1,3,13\n" +
- "1,5,15\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";
- }
-
- @Test
- public void testAddVertexNoEdges() throws Exception {
- /*
- * Test addVertex() -- add vertex with empty edge set
- */
-
- final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-
- Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
- TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
- graph = graph.addVertex(new Vertex<Long, Long>(6L, 6L), edges);
- graph.getVertices().writeAsCsv(resultPath);
- env.execute();
-
- expectedResult = "1,1\n" +
- "2,2\n" +
- "3,3\n" +
- "4,4\n" +
- "5,5\n" +
- "6,6\n";
- }
-
- @Test
- public void testAddVerticesNoEdges() throws Exception {
- /*
- * Test addVertices() -- add vertices with empty edge set
- */
-
- final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-
- Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
- TestGraphUtils.getLongLongEdgeData(env), env);
- List<Edge<Long, Long>> edges = new ArrayList<Edge<Long, Long>>();
-
- DataSet<Vertex<Long, Long>> newVertices = env.fromElements(new Vertex<Long, Long>(6L, 6L),
- new Vertex<Long, Long>(7L, 7L));
- graph = graph.addVertices(newVertices, edges);
+ graph = graph.addVertices(vertices);
graph.getVertices().writeAsCsv(resultPath);
env.execute();
@@ -259,8 +183,7 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
"3,3\n" +
"4,4\n" +
"5,5\n" +
- "6,6\n" +
- "7,7\n";
+ "6,6\n";
}
@Test
@@ -293,8 +216,10 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Vertex<Long, Long>> verticesToBeRemoved = env.fromElements(new Vertex<Long, Long>(1L, 1L),
- new Vertex<Long, Long>(2L, 2L));
+
+ List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<Vertex<Long, Long>>();
+ verticesToBeRemoved.add(new Vertex<Long, Long>(1L, 1L));
+ verticesToBeRemoved.add(new Vertex<Long, Long>(2L, 2L));
graph = graph.removeVertices(verticesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);
@@ -338,8 +263,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Vertex<Long, Long>> verticesToBeRemoved = env.fromElements(new Vertex<Long, Long>(1L, 1L),
- new Vertex<Long, Long>(7L, 7L));
+ List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<Vertex<Long, Long>>();
+ verticesToBeRemoved.add(new Vertex<Long, Long>(1L, 1L));
+ verticesToBeRemoved.add(new Vertex<Long, Long>(7L, 7L));
graph = graph.removeVertices(verticesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);
@@ -361,8 +287,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Vertex<Long, Long>> verticesToBeRemoved = env.fromElements(new Vertex<Long, Long>(6L, 6L),
- new Vertex<Long, Long>(7L, 7L));
+ List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<Vertex<Long, Long>>();
+ verticesToBeRemoved.add(new Vertex<Long, Long>(6L, 6L));
+ verticesToBeRemoved.add(new Vertex<Long, Long>(7L, 7L));
graph = graph.removeVertices(verticesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);
@@ -387,8 +314,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Vertex<Long, Long>> verticesToBeRemoved = env.fromElements(new Vertex<Long, Long>(6L, 6L),
- new Vertex<Long, Long>(7L, 7L));
+ List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<Vertex<Long, Long>>();
+ verticesToBeRemoved.add(new Vertex<Long, Long>(6L, 6L));
+ verticesToBeRemoved.add(new Vertex<Long, Long>(7L, 7L));
graph = graph.removeVertices(verticesToBeRemoved);
graph.getVertices().writeAsCsv(resultPath);
@@ -437,12 +365,11 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Edge<Long, Long>> edgesToBeAdded = env.fromElements(new Edge<Long, Long>(6L, 1L, 61L),
- new Edge<Long, Long>(7L, 1L, 71L));
- DataSet<Vertex<Long, Long>> verticesToBeAdded = env.fromElements(new Vertex<Long, Long>(6L, 6L),
- new Vertex<Long, Long>(7L, 7L));
+ List<Edge<Long, Long>> edgesToBeAdded = new ArrayList<Edge<Long, Long>>();
+ edgesToBeAdded.add(new Edge<Long, Long>(2L, 4L, 24L));
+ edgesToBeAdded.add(new Edge<Long, Long>(4L, 1L, 41L));
- graph = graph.addEdges(edgesToBeAdded, verticesToBeAdded);
+ graph = graph.addEdges(edgesToBeAdded);
graph.getEdges().writeAsCsv(resultPath);
env.execute();
@@ -450,12 +377,41 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
expectedResult = "1,2,12\n" +
"1,3,13\n" +
"2,3,23\n" +
+ "2,4,24\n" +
"3,4,34\n" +
"3,5,35\n" +
+ "4,1,41\n" +
"4,5,45\n" +
- "5,1,51\n" +
- "6,1,61\n" +
- "7,1,71\n";
+ "5,1,51\n";
+ }
+
+ @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<Edge<Long, Long>>();
+ edgesToBeAdded.add(new Edge<Long, Long>(6L, 1L, 61L));
+ edgesToBeAdded.add(new Edge<Long, Long>(7L, 1L, 71L));
+
+ graph = graph.addEdges(edgesToBeAdded);
+
+ graph.getEdges().writeAsCsv(resultPath);
+ env.execute();
+
+ 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";
}
@Test
@@ -515,8 +471,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Edge<Long, Long>> edgesToBeRemoved = env.fromElements(new Edge<Long, Long>(5L, 1L, 51L),
- new Edge<Long, Long>(2L, 3L, 23L));
+ List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<Edge<Long, Long>>();
+ edgesToBeRemoved.add(new Edge<Long, Long>(5L, 1L, 51L));
+ edgesToBeRemoved.add(new Edge<Long, Long>(2L, 3L, 23L));
graph = graph.removeEdges(edgesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);
@@ -539,8 +496,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Edge<Long, Long>> edgesToBeRemoved = env.fromElements(new Edge<Long, Long>(5L, 1L, 51L),
- new Edge<Long, Long>(5L, 1L, 51L));
+ List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<Edge<Long, Long>>();
+ edgesToBeRemoved.add(new Edge<Long, Long>(5L, 1L, 51L));
+ edgesToBeRemoved.add(new Edge<Long, Long>(5L, 1L, 51L));
graph = graph.removeEdges(edgesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);
@@ -587,8 +545,9 @@ public class GraphMutationsITCase extends MultipleProgramsTestBase {
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
TestGraphUtils.getLongLongEdgeData(env), env);
- DataSet<Edge<Long, Long>> edgesToBeRemoved = env.fromElements(new Edge<Long, Long>(1L, 1L, 51L),
- new Edge<Long, Long>(6L, 1L, 61L));
+ List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<Edge<Long, Long>>();
+ edgesToBeRemoved.add(new Edge<Long, Long>(1L, 1L, 51L));
+ edgesToBeRemoved.add(new Edge<Long, Long>(6L, 1L, 61L));
graph = graph.removeEdges(edgesToBeRemoved);
graph.getEdges().writeAsCsv(resultPath);