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/05 19:40:01 UTC
[1/4] flink git commit: [FLINK-1944] [gelly] Added GSA-PageRank
example
Repository: flink
Updated Branches:
refs/heads/master bdd842961 -> 60ec68308
[FLINK-1944] [gelly] Added GSA-PageRank example
This closes #626
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/7d2e5aa9
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/7d2e5aa9
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/7d2e5aa9
Branch: refs/heads/master
Commit: 7d2e5aa9d992e9cfaeaf3fdb9f3d2cc776e152b4
Parents: bdd8429
Author: andralungu <lu...@gmail.com>
Authored: Mon Apr 27 00:26:41 2015 +0200
Committer: vasia <va...@apache.org>
Committed: Tue May 5 17:11:08 2015 +0200
----------------------------------------------------------------------
.../apache/flink/graph/example/GSAPageRank.java | 209 +++++++++++++++++++
.../flink/graph/example/PageRankExample.java | 8 +-
.../apache/flink/graph/gsa/ApplyFunction.java | 16 +-
.../apache/flink/graph/gsa/GatherFunction.java | 16 +-
.../org/apache/flink/graph/gsa/SumFunction.java | 16 +-
.../flink/graph/test/GatherSumApplyITCase.java | 16 ++
6 files changed, 265 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
new file mode 100644
index 0000000..b6f0c87
--- /dev/null
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.graph.example;
+
+import org.apache.flink.api.common.ProgramDescription;
+import org.apache.flink.api.common.functions.FlatMapFunction;
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.graph.Edge;
+import org.apache.flink.graph.Graph;
+import org.apache.flink.graph.Vertex;
+import org.apache.flink.graph.gsa.ApplyFunction;
+import org.apache.flink.graph.gsa.GatherFunction;
+import org.apache.flink.graph.gsa.Neighbor;
+import org.apache.flink.graph.gsa.SumFunction;
+import org.apache.flink.graph.utils.Tuple3ToEdgeMap;
+import org.apache.flink.util.Collector;
+
+/**
+ * This example implements a simple PageRank algorithm, using a gather-sum-apply iteration.
+ *
+ * The edges input file is expected to contain one edge per line, with long IDs and double
+ * values, in the following format:"<sourceVertexID>\t<targetVertexID>\t<edgeValue>".
+ *
+ * If no arguments are provided, the example runs with a random graph of 10 vertices
+ * and random edge weights.
+ */
+public class GSAPageRank implements ProgramDescription {
+
+ public static void main(String[] args) throws Exception {
+
+ if(!parseParameters(args)) {
+ return;
+ }
+
+ ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+
+ DataSet<Edge<Long, Double>> links = getLinksDataSet(env);
+
+ Graph<Long, Double, Double> network = Graph.fromDataSet(links, new MapFunction<Long, Double>() {
+
+ @Override
+ public Double map(Long value) throws Exception {
+ return 1.0;
+ }
+ }, env);
+
+ DataSet<Tuple2<Long, Long>> vertexOutDegrees = network.outDegrees();
+
+ // Assign the transition probabilities as the edge weights
+ Graph<Long, Double, Double> networkWithWeights = network
+ .joinWithEdgesOnSource(vertexOutDegrees,
+ new MapFunction<Tuple2<Double, Long>, Double>() {
+
+ @Override
+ public Double map(Tuple2<Double, Long> value) {
+ return value.f0 / value.f1;
+ }
+ });
+
+ long numberOfVertices = networkWithWeights.numberOfVertices();
+
+ // Execute the GSA iteration
+ Graph<Long, Double, Double> result = networkWithWeights
+ .runGatherSumApplyIteration(new GatherRanks(numberOfVertices), new SumRanks(),
+ new UpdateRanks(numberOfVertices), maxIterations);
+
+ // Extract the vertices as the result
+ DataSet<Vertex<Long, Double>> pageRanks = result.getVertices();
+
+ // emit result
+ if (fileOutput) {
+ pageRanks.writeAsCsv(outputPath, "\n", "\t");
+ } else {
+ pageRanks.print();
+ }
+
+ env.execute("GSA Page Ranks");
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Page Rank UDFs
+ // --------------------------------------------------------------------------------------------
+
+ @SuppressWarnings("serial")
+ private static final class GatherRanks extends GatherFunction<Double, Double, Double> {
+
+ long numberOfVertices;
+
+ public GatherRanks(long numberOfVertices) {
+ this.numberOfVertices = numberOfVertices;
+ }
+
+ @Override
+ public Double gather(Neighbor<Double, Double> neighbor) {
+ double neighborRank = neighbor.getNeighborValue();
+
+ if(getSuperstepNumber() == 1) {
+ neighborRank = 1.0 / numberOfVertices;
+ }
+
+ return neighborRank * neighbor.getEdgeValue();
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static final class SumRanks extends SumFunction<Double, Double, Double> {
+
+ @Override
+ public Double sum(Double newValue, Double currentValue) {
+ return newValue + currentValue;
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static final class UpdateRanks extends ApplyFunction<Long, Double, Double> {
+
+ long numberOfVertices;
+
+ public UpdateRanks(long numberOfVertices) {
+ this.numberOfVertices = numberOfVertices;
+ }
+
+ @Override
+ public void apply(Double rankSum, Double currentValue) {
+ setResult((1-DAMPENING_FACTOR)/numberOfVertices + DAMPENING_FACTOR * rankSum);
+ }
+ }
+
+ // *************************************************************************
+ // UTIL METHODS
+ // *************************************************************************
+
+ private static boolean fileOutput = false;
+ private static final double DAMPENING_FACTOR = 0.85;
+ private static long numPages = 10;
+ private static String edgeInputPath = null;
+ private static String outputPath = null;
+ private static int maxIterations = 10;
+
+ private static boolean parseParameters(String[] args) {
+
+ if(args.length > 0) {
+ if(args.length != 3) {
+ System.err.println("Usage: GSAPageRank <input edges path> <output path> <num iterations>");
+ return false;
+ }
+
+ fileOutput = true;
+ edgeInputPath = args[0];
+ outputPath = args[1];
+ maxIterations = Integer.parseInt(args[2]);
+ } else {
+ System.out.println("Executing GSAPageRank example with default parameters and built-in default data.");
+ System.out.println(" Provide parameters to read input data from files.");
+ System.out.println(" See the documentation for the correct format of input files.");
+ System.out.println(" Usage: GSAPageRank <input edges path> <output path> <num iterations>");
+ }
+ return true;
+ }
+
+ @SuppressWarnings("serial")
+ private static DataSet<Edge<Long, Double>> getLinksDataSet(ExecutionEnvironment env) {
+
+ if (fileOutput) {
+ return env.readCsvFile(edgeInputPath)
+ .fieldDelimiter("\t")
+ .lineDelimiter("\n")
+ .types(Long.class, Long.class, Double.class)
+ .map(new Tuple3ToEdgeMap<Long, Double>());
+ }
+
+ return env.generateSequence(1, numPages).flatMap(
+ new FlatMapFunction<Long, Edge<Long, Double>>() {
+ @Override
+ public void flatMap(Long key,
+ Collector<Edge<Long, Double>> out) throws Exception {
+ int numOutEdges = (int) (Math.random() * (numPages / 2));
+ for (int i = 0; i < numOutEdges; i++) {
+ long target = (long) (Math.random() * numPages) + 1;
+ out.collect(new Edge<Long, Double>(key, target, 1.0));
+ }
+ }
+ });
+ }
+
+ @Override
+ public String getDescription() {
+ return "GSA Page Rank";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/PageRankExample.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/PageRankExample.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/PageRankExample.java
index cc0b702..2e36ad9 100644
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/PageRankExample.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/PageRankExample.java
@@ -104,15 +104,15 @@ public class PageRankExample implements ProgramDescription {
private static boolean parseParameters(String[] args) {
if(args.length > 0) {
- if(args.length != 4) {
+ if(args.length != 3) {
System.err.println("Usage: PageRank <input edges path> <output path> <num iterations>");
return false;
}
fileOutput = true;
- edgeInputPath = args[1];
- outputPath = args[2];
- maxIterations = Integer.parseInt(args[3]);
+ edgeInputPath = args[0];
+ outputPath = args[1];
+ maxIterations = Integer.parseInt(args[2]);
} else {
System.out.println("Executing PageRank example with default parameters and built-in default data.");
System.out.println(" Provide parameters to read input data from files.");
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/ApplyFunction.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/ApplyFunction.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/ApplyFunction.java
index 75f64f9..a4963e0 100755
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/ApplyFunction.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/ApplyFunction.java
@@ -45,20 +45,28 @@ public abstract class ApplyFunction<K extends Comparable<K> & Serializable, VV e
*
* @throws Exception Exceptions in the pre-superstep phase cause the superstep to fail.
*/
- public void preSuperstep() {};
+ public void preSuperstep() {}
/**
* This method is executed once per superstep after the vertex update function has been invoked for each vertex.
*
* @throws Exception Exceptions in the post-superstep phase cause the superstep to fail.
*/
- public void postSuperstep() {};
+ public void postSuperstep() {}
+
+ /**
+ * Gets the number of the superstep, starting at <tt>1</tt>.
+ *
+ * @return The number of the current superstep.
+ */
+ public int getSuperstepNumber() {
+ return this.runtimeContext.getSuperstepNumber();
+ }
// --------------------------------------------------------------------------------------------
// Internal methods
// --------------------------------------------------------------------------------------------
- @SuppressWarnings("unused")
private IterationRuntimeContext runtimeContext;
private Collector<Vertex<K, VV>> out;
@@ -67,7 +75,7 @@ public abstract class ApplyFunction<K extends Comparable<K> & Serializable, VV e
public void init(IterationRuntimeContext iterationRuntimeContext) {
this.runtimeContext = iterationRuntimeContext;
- };
+ }
public void setOutput(Vertex<K, VV> vertex, Collector<Vertex<K, VV>> out) {
this.out = out;
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/GatherFunction.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/GatherFunction.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/GatherFunction.java
index 0b0caf9..4ffae8d 100755
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/GatherFunction.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/GatherFunction.java
@@ -32,23 +32,31 @@ public abstract class GatherFunction<VV extends Serializable, EV extends Seriali
*
* @throws Exception Exceptions in the pre-superstep phase cause the superstep to fail.
*/
- public void preSuperstep() {};
+ public void preSuperstep() {}
/**
* This method is executed once per superstep after the vertex update function has been invoked for each vertex.
*
* @throws Exception Exceptions in the post-superstep phase cause the superstep to fail.
*/
- public void postSuperstep() {};
+ public void postSuperstep() {}
+
+ /**
+ * Gets the number of the superstep, starting at <tt>1</tt>.
+ *
+ * @return The number of the current superstep.
+ */
+ public int getSuperstepNumber() {
+ return this.runtimeContext.getSuperstepNumber();
+ }
// --------------------------------------------------------------------------------------------
// Internal methods
// --------------------------------------------------------------------------------------------
- @SuppressWarnings("unused")
private IterationRuntimeContext runtimeContext;
public void init(IterationRuntimeContext iterationRuntimeContext) {
this.runtimeContext = iterationRuntimeContext;
- };
+ }
}
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/SumFunction.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/SumFunction.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/SumFunction.java
index 6ed85c4..4836af6 100755
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/SumFunction.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/gsa/SumFunction.java
@@ -32,23 +32,31 @@ public abstract class SumFunction<VV extends Serializable, EV extends Serializab
*
* @throws Exception Exceptions in the pre-superstep phase cause the superstep to fail.
*/
- public void preSuperstep() {};
+ public void preSuperstep() {}
/**
* This method is executed once per superstep after the vertex update function has been invoked for each vertex.
*
* @throws Exception Exceptions in the post-superstep phase cause the superstep to fail.
*/
- public void postSuperstep() {};
+ public void postSuperstep() {}
+
+ /**
+ * Gets the number of the superstep, starting at <tt>1</tt>.
+ *
+ * @return The number of the current superstep.
+ */
+ public int getSuperstepNumber() {
+ return this.runtimeContext.getSuperstepNumber();
+ }
// --------------------------------------------------------------------------------------------
// Internal methods
// --------------------------------------------------------------------------------------------
- @SuppressWarnings("unused")
private IterationRuntimeContext runtimeContext;
public void init(IterationRuntimeContext iterationRuntimeContext) {
this.runtimeContext = iterationRuntimeContext;
- };
+ }
}
http://git-wip-us.apache.org/repos/asf/flink/blob/7d2e5aa9/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/GatherSumApplyITCase.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/GatherSumApplyITCase.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/GatherSumApplyITCase.java
index 23ebfa5..a0c1de4 100755
--- a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/GatherSumApplyITCase.java
+++ b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/GatherSumApplyITCase.java
@@ -21,6 +21,7 @@ package org.apache.flink.graph.test;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.flink.graph.example.GSAConnectedComponentsExample;
+import org.apache.flink.graph.example.GSAPageRank;
import org.apache.flink.graph.example.GSASingleSourceShortestPathsExample;
import org.apache.flink.test.util.MultipleProgramsTestBase;
import org.junit.After;
@@ -96,6 +97,21 @@ public class GatherSumApplyITCase extends MultipleProgramsTestBase {
"7 Infinity\n";
}
+ // --------------------------------------------------------------------------------------------
+ // Page Rank Test
+ // --------------------------------------------------------------------------------------------
+
+ @Test
+ public void testPageRank() throws Exception {
+ GSAPageRank.main(new String[]{edgesPath, resultPath, "16"});
+ expectedResult = "1 7.47880014315678E21\n" +
+ "2 1.6383884499619055E21\n" +
+ "3 3.044048626469292E21\n" +
+ "4 1.6896936994425786E21\n" +
+ "5 4.214827876275491E21\n" +
+ "6 1.0\n" +
+ "7 8.157142857142858";
+ }
// --------------------------------------------------------------------------------------------
// Sample data
[3/4] flink git commit: [FLINK-1871] [gelly] Added Spargel to Gelly
migration guide
Posted by va...@apache.org.
[FLINK-1871] [gelly] Added Spargel to Gelly migration guide
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/0163e500
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/0163e500
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/0163e500
Branch: refs/heads/master
Commit: 0163e500c94737986e72c502fe961d0008e629fd
Parents: 51aa666
Author: andralungu <lu...@gmail.com>
Authored: Tue Apr 14 18:22:48 2015 +0200
Committer: vasia <va...@apache.org>
Committed: Tue May 5 17:11:28 2015 +0200
----------------------------------------------------------------------
docs/libs/gelly_guide.md | 105 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/0163e500/docs/libs/gelly_guide.md
----------------------------------------------------------------------
diff --git a/docs/libs/gelly_guide.md b/docs/libs/gelly_guide.md
index 6ea7dc7..a52b40c 100644
--- a/docs/libs/gelly_guide.md
+++ b/docs/libs/gelly_guide.md
@@ -440,6 +440,111 @@ public static final class Messenger extends MessagingFunction {...}
[Back to top](#top)
+Migrating Spargel Code to Gelly
+-----------
+
+Due to the natural mapping of Spargel components to Gelly components, applications can easily be migrated from one API to the other.
+General guidelines:
+* <strong>Vertex and Edge Abstractions</strong>: In Spargel, vertices and edges are defined using tuples (Tuple2 for vertices, Tuple2 for edges without values, Tuple3 for edges with values). Gelly presents a more intuitive vertex and edge representation by introducing the `Vertex` and `Edge` types. A `Vertex` is defined by an id and a value. If no value is provided, the value type should be set to `NullValue`. An `Edge` is defined by a source id, a target id and a value. Since the source and target values are of the same type, only two type parameters are needed. If no value is provided, the value type should be set to `NullValue`.
+
+* <strong>Methods for Plain Edges and for Valued Edges</strong>: In Spargel, there are separate methods for edges with values and edges without values when running the vertex centric iteration (i.e. `withValuedEdges()`, `withPlainEdges()`). In Gelly, this distinction no longer needs to be made because an edge with no value will simply have a `NullValue` type.
+
+* <strong>OutgoingEdge versus Edge</strong>: Spargel's `OutgoingEdge` is replaced by `Edge` in Gelly.
+
+* <strong>Running a Vertex Centric Iteration</strong>: In Spargel, an iteration is ran by calling the `runOperation()` method on a `VertexCentricIteration`. The edge type (plain or valued) dictates the method to be called. The arguments are: a data set of edges, the vertex update function, the messaging function and the maximum number of iterations. The result is a DataSet<Tuple2<vertexId, vertexValue>> representing the updated vertices.
+In Gelly, an iteration is ran by calling `runVertexCentricIteration()` on a graph. The parameters given to this method are the vertex update function, the messaging function and the maximum number of iterations. The result is a new graph with updated vertex values.
+
+* <strong>Configuring a Vertex Centric Iteration</strong>: In Spargel, an iteration is configured by directly setting a set of parameters on the VertexCentricIteration instance (e.g. `iteration.setName("Spargel Iteration")`). In Gelly, a vertex-centric iteration is configured using the `IterationConfiguration` object (e.g. iterationConfiguration.setName("Gelly Iteration")). An instance of this object is then passed as a final parameter to the `runVertexCentricIteration()` method.
+
+* <strong>Record API</strong>: Spargel's Record API was completely removed from Gelly.
+
+In the following section, we present a step-by-step tutorial for moving the connected components algorithm from Spargel to Gelly.
+
+In Spargel, the edges and vertices are defined by a `DataSet<Tuple2<IdType, EdgeValue>>` and a `DataSet<Tuple2<IdType, VertexValue>>` respectively.
+
+{% highlight java %}
+ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+DataSet<Tuple2<Long, Long>> edges = ...
+DataSet<Tuple2<Long, Long>> initialVertices = vertexIds.map(new IdAssigner());
+
+DataSet<Tuple2<Long, Long>> result = initialVertices.runOperation(VertexCentricIteration.withPlainEdges(edges, new CCUpdater(), new CCMessenger(), maxIterations));
+
+result.print();
+env.execute("Spargel Connected Components");
+{% endhighlight %}
+
+In this algorithm, initially, each vertex has its own ID as a value (is in its own component).
+Hence, the need for `IdAssigner()` user defined function which is simply a map that takes a value and creates a tuple (value,value) out of it.
+
+<p class="text-center">
+ <img alt="Spargel Example Input" width="75%" src="img/spargel_example_input.png" />
+</p>
+
+In Gelly, the edges and vertices have a more intuitive definition: they are represented by separate types `Edge`, `Vertex`.
+After defining the edge data set, we can create a Graph from it.
+
+{% highlight java %}
+ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+DataSet<Edge<Long, NullValue>> edges = ...
+
+Graph<Long, Long, NullValue> graph = Graph.fromDataSet(edges, new MapFunction<Long, Long>() {
+ @Override
+ public Long map(Long value) throws Exception {
+ return value;
+ }
+ }, env);
+
+DataSet<Vertex<Long, Long>> result = graph.runVertexCentricIteration(new CCUpdater(),
+ new CCMessenger(), maxIterations).getVertices();
+
+result.print();
+env.execute("Gelly Connected Components");
+{% endhighlight %}
+
+Notice that when assigning the initial vertex IDs, there is no need to perform a separate map operation. The value is specified directly in the `fromDataSet()` method.
+Instead of calling `runOperation()` on the set of vertices, `runVertexCentricIteration()` is called on the graph instance.
+As previously stated, `runVertexCentricIteration` returns a new graph with the updated vertex values. In order to retrieve the result (since for this algorithm we are only interested in the vertex ids and their corresponding values), we will call the `getVertices()` method.
+
+In the connected components algorithm, the vertices propagate their current component ID in iterations, each time adopting a new value from the received neighbor IDs, provided that the value is smaller than the current minimum.
+To this end, we iterate over all received messages and update the vertex value, if necessary:
+
+{% highlight java %}
+public static final class CCUpdater extends VertexUpdateFunction<Long, Long, Long> {
+ @Override
+ public void updateVertex(Long vertexKey, Long vertexValue, MessageIterator<Long> inMessages) {
+ long min = Long.MAX_VALUE;
+ for (long msg : inMessages) {
+ min = Math.min(min, msg);
+ }
+ if (min < vertexValue) {
+ setNewVertexValue(min);
+ }
+ }
+}
+{% endhighlight %}
+
+The **messages in each superstep** consist of the **current component ID** seen by the vertex:
+{% highlight java %}
+public static final class CCMessenger extends MessagingFunction<Long, Long, Long, NullValue> {
+ @Override
+ public void sendMessages(Long vertexId, Long componentId) {
+ sendMessageToAllNeighbors(componentId);
+ }
+}
+{% endhighlight %}
+
+The fact that the two names for the `VertexUpdateFunction` and for the `MessagingFunction`: `CCUpdater` and `CCMessenger` coincide in Spargel's `runOperation()` and in Gelly's `runVertexCentricIteration()` implies that the classes defined for the Spargel algortihm remain unchanged in Gelly.
+
+Similarly to Spargel, if the value of a vertex does not change during a superstep, it will **not send** any messages in the superstep. This allows to do incremental updates to the **hot (changing) parts** of the graph, while leaving **cold (steady) parts** untouched.
+
+The computation **terminates** after a specified *maximum number of supersteps* **-OR-** when the *vertex states stop changing*.
+
+<p class="text-center">
+ <img alt="Spargel Example" width="75%" src="img/spargel_example.png" />
+</p>
+
+[Back to top](#top)
+
Graph Validation
-----------
[2/4] flink git commit: [gelly] [docs] Change the return type of
groupReduceOnNeighbors example
Posted by va...@apache.org.
[gelly] [docs] Change the return type of groupReduceOnNeighbors example
This closes #650
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/51aa6661
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/51aa6661
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/51aa6661
Branch: refs/heads/master
Commit: 51aa6661a156a7f7b4be7aaa1913963866a5e9a6
Parents: 7d2e5aa
Author: joey001 <zh...@gmail.com>
Authored: Mon May 4 22:12:54 2015 +0200
Committer: vasia <va...@apache.org>
Committed: Tue May 5 17:11:28 2015 +0200
----------------------------------------------------------------------
docs/libs/gelly_guide.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/51aa6661/docs/libs/gelly_guide.md
----------------------------------------------------------------------
diff --git a/docs/libs/gelly_guide.md b/docs/libs/gelly_guide.md
index 91f0978..6ea7dc7 100644
--- a/docs/libs/gelly_guide.md
+++ b/docs/libs/gelly_guide.md
@@ -325,7 +325,7 @@ For example, the following code will output all the vertex pairs which are conne
{% highlight java %}
Graph<Long, Long, Double> graph = ...
-DataSet<Tuple2<Long, Long>> vertexPairs = graph.groupReduceOnNeighbors(new SelectLargeWeightNeighbors(), EdgeDirection.OUT);
+DataSet<Tuple2<Vertex<Long, Long>, Vertex<Long, Long>>> vertexPairs = graph.groupReduceOnNeighbors(new SelectLargeWeightNeighbors(), EdgeDirection.OUT);
// user-defined function to select the neighbors which have edges with weight > 0.5
static final class SelectLargeWeightNeighbors implements NeighborsFunctionWithVertexValue<Long, Long, Double,
[4/4] flink git commit: [FLINK-1871] [gelly] [docs] added a link to
the migration guide in the Spargel guide;
moved the migration guide section to the end of Gelly guide;
made a few corrections in the migration guide text
Posted by va...@apache.org.
[FLINK-1871] [gelly] [docs] added a link to the migration guide in the Spargel guide;
moved the migration guide section to the end of Gelly guide;
made a few corrections in the migration guide text
This closes #600
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/60ec6830
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/60ec6830
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/60ec6830
Branch: refs/heads/master
Commit: 60ec683082124359162ac3c97b223b5cfe44cbbd
Parents: 0163e50
Author: vasia <va...@apache.org>
Authored: Tue May 5 17:04:31 2015 +0200
Committer: vasia <va...@apache.org>
Committed: Tue May 5 17:15:16 2015 +0200
----------------------------------------------------------------------
docs/libs/gelly_guide.md | 154 ++++++++++---------
docs/libs/spargel_guide.md | 4 +-
.../example/ConnectedComponentsExample.java | 1 +
.../apache/flink/graph/example/GSAPageRank.java | 1 +
4 files changed, 86 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/60ec6830/docs/libs/gelly_guide.md
----------------------------------------------------------------------
diff --git a/docs/libs/gelly_guide.md b/docs/libs/gelly_guide.md
index a52b40c..8292968 100644
--- a/docs/libs/gelly_guide.md
+++ b/docs/libs/gelly_guide.md
@@ -440,50 +440,109 @@ public static final class Messenger extends MessagingFunction {...}
[Back to top](#top)
+
+Graph Validation
+-----------
+
+Gelly provides a simple utility for performing validation checks on input graphs. Depending on the application context, a graph may or may not be valid according to certain criteria. For example, a user might need to validate whether their graph contains duplicate edges or whether its structure is bipartite. In order to validate a graph, one can define a custom `GraphValidator` and implement its `validate()` method. `InvalidVertexIdsValidator` is Gelly's pre-defined validator. It checks that the edge set contains valid vertex IDs, i.e. that all edge IDs
+also exist in the vertex IDs set.
+
+{% highlight java %}
+ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+
+// create a list of vertices with IDs = {1, 2, 3, 4, 5}
+List<Vertex<Long, Long>> vertices = ...
+
+// create a list of edges with IDs = {(1, 2) (1, 3), (2, 4), (5, 6)}
+List<Edge<Long, Long>> edges = ...
+
+Graph<Long, Long, Long> graph = Graph.fromCollection(vertices, edges, env);
+
+// will return false: 6 is an invalid ID
+graph.validate(new InvalidVertexIdsValidator<Long, Long, Long>());
+
+{% endhighlight %}
+
+[Back to top](#top)
+
+Library Methods
+-----------
+Gelly has a growing collection of graph algorithms for easily analyzing large-scale Graphs. So far, the following library methods are implemented:
+
+* PageRank
+* Single-Source Shortest Paths
+* Label Propagation
+* Simple Community Detection
+* Connected Components
+
+Gelly's library methods can be used by simply calling the `run()` method on the input graph:
+
+{% highlight java %}
+ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+
+Graph<Long, Long, NullValue> graph = ...
+
+// run Label Propagation for 30 iterations to detect communities on the input graph
+DataSet<Vertex<Long, Long>> verticesWithCommunity = graph.run(
+ new LabelPropagation<Long>(30)).getVertices();
+
+// print the result
+verticesWithCommunity.print();
+
+env.execute();
+{% endhighlight %}
+
+[Back to top](#top)
+
Migrating Spargel Code to Gelly
-----------
-Due to the natural mapping of Spargel components to Gelly components, applications can easily be migrated from one API to the other.
-General guidelines:
-* <strong>Vertex and Edge Abstractions</strong>: In Spargel, vertices and edges are defined using tuples (Tuple2 for vertices, Tuple2 for edges without values, Tuple3 for edges with values). Gelly presents a more intuitive vertex and edge representation by introducing the `Vertex` and `Edge` types. A `Vertex` is defined by an id and a value. If no value is provided, the value type should be set to `NullValue`. An `Edge` is defined by a source id, a target id and a value. Since the source and target values are of the same type, only two type parameters are needed. If no value is provided, the value type should be set to `NullValue`.
+Gelly provides the old Spargel API functionality through its vertex-centric iteration methods. Applications can be easily migrated from one API to the other, using the following
+general guidelines:
-* <strong>Methods for Plain Edges and for Valued Edges</strong>: In Spargel, there are separate methods for edges with values and edges without values when running the vertex centric iteration (i.e. `withValuedEdges()`, `withPlainEdges()`). In Gelly, this distinction no longer needs to be made because an edge with no value will simply have a `NullValue` type.
+* <strong>Vertex and Edge Types</strong>: In Spargel, vertices and edges are defined using tuples (`Tuple2` for vertices, `Tuple2` for edges without values, `Tuple3` for edges with values). Gelly has a more intuitive [graph representation](#graph-representation) by introducing the `Vertex` and `Edge` types.
-* <strong>OutgoingEdge versus Edge</strong>: Spargel's `OutgoingEdge` is replaced by `Edge` in Gelly.
+* <strong>Methods for Plain Edges and for Valued Edges</strong>: In Spargel, there are separate methods for edges with values and edges without values when running the vertex centric iteration (i.e. `withValuedEdges()`, `withPlainEdges()`). In Gelly, this distinction is no longer needede because an edge with no value will simply have a `NullValue` type.
-* <strong>Running a Vertex Centric Iteration</strong>: In Spargel, an iteration is ran by calling the `runOperation()` method on a `VertexCentricIteration`. The edge type (plain or valued) dictates the method to be called. The arguments are: a data set of edges, the vertex update function, the messaging function and the maximum number of iterations. The result is a DataSet<Tuple2<vertexId, vertexValue>> representing the updated vertices.
-In Gelly, an iteration is ran by calling `runVertexCentricIteration()` on a graph. The parameters given to this method are the vertex update function, the messaging function and the maximum number of iterations. The result is a new graph with updated vertex values.
+* <strong>OutgoingEdge</strong>: Spargel's `OutgoingEdge` is replaced by `Edge` in Gelly.
-* <strong>Configuring a Vertex Centric Iteration</strong>: In Spargel, an iteration is configured by directly setting a set of parameters on the VertexCentricIteration instance (e.g. `iteration.setName("Spargel Iteration")`). In Gelly, a vertex-centric iteration is configured using the `IterationConfiguration` object (e.g. iterationConfiguration.setName("Gelly Iteration")). An instance of this object is then passed as a final parameter to the `runVertexCentricIteration()` method.
+* <strong>Running a Vertex Centric Iteration</strong>: In Spargel, an iteration is run by calling the `runOperation()` method on a `VertexCentricIteration`. The edge type (plain or valued) dictates the method to be called. The arguments are: a data set of edges, the vertex update function, the messaging function and the maximum number of iterations. The result is a `DataSet<Tuple2<vertexId, vertexValue>>` representing the updated vertices.
+In Gelly, an iteration is run by calling `runVertexCentricIteration()` on a `Graph`. The parameters given to this method are the vertex update function, the messaging function and the maximum number of iterations. The result is a new `Graph` with updated vertex values.
+
+* <strong>Configuring a Vertex Centric Iteration</strong>: In Spargel, an iteration is configured by directly setting a set of parameters on the `VertexCentricIteration` instance (e.g. `iteration.setName("Spargel Iteration")`). In Gelly, a vertex-centric iteration is configured using the `IterationConfiguration` object (e.g. `iterationConfiguration.setName("Gelly Iteration”)`). An instance of this object is then passed as a final parameter to the `runVertexCentricIteration()` method.
* <strong>Record API</strong>: Spargel's Record API was completely removed from Gelly.
-In the following section, we present a step-by-step tutorial for moving the connected components algorithm from Spargel to Gelly.
+In the following section, we present a step-by-step example for porting the Connected Components algorithm from Spargel to Gelly.
-In Spargel, the edges and vertices are defined by a `DataSet<Tuple2<IdType, EdgeValue>>` and a `DataSet<Tuple2<IdType, VertexValue>>` respectively.
+In Spargel, the edges and vertices are defined by a `DataSet<Tuple2<IdType, EdgeValue>>` and a `DataSet<Tuple2<IdType, VertexValue>>` respectively:
{% highlight java %}
+// Spargel API
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Long, Long>> edges = ...
DataSet<Tuple2<Long, Long>> initialVertices = vertexIds.map(new IdAssigner());
-DataSet<Tuple2<Long, Long>> result = initialVertices.runOperation(VertexCentricIteration.withPlainEdges(edges, new CCUpdater(), new CCMessenger(), maxIterations));
+DataSet<Tuple2<Long, Long>> result = initialVertices.runOperation(
+ VertexCentricIteration.withPlainEdges(edges, new CCUpdater(), new CCMessenger(),
+ maxIterations));
result.print();
env.execute("Spargel Connected Components");
{% endhighlight %}
In this algorithm, initially, each vertex has its own ID as a value (is in its own component).
-Hence, the need for `IdAssigner()` user defined function which is simply a map that takes a value and creates a tuple (value,value) out of it.
+Hence, the need for `IdAssigner()`, which is used to initialize the vertex values.
<p class="text-center">
- <img alt="Spargel Example Input" width="75%" src="img/spargel_example_input.png" />
+ <img alt="Spargel Example Input" width="75%" src="fig/spargel_example_input.png" />
</p>
In Gelly, the edges and vertices have a more intuitive definition: they are represented by separate types `Edge`, `Vertex`.
-After defining the edge data set, we can create a Graph from it.
+After defining the edge data set, we can create a `Graph` from it.
{% highlight java %}
+// Gelly API
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Edge<Long, NullValue>> edges = ...
@@ -494,18 +553,20 @@ Graph<Long, Long, NullValue> graph = Graph.fromDataSet(edges, new MapFunction<Lo
}
}, env);
-DataSet<Vertex<Long, Long>> result = graph.runVertexCentricIteration(new CCUpdater(),
- new CCMessenger(), maxIterations).getVertices();
+DataSet<Vertex<Long, Long>> result = graph.runVertexCentricIteration(new CCUpdater(), new CCMessenger(), maxIterations)
+ .getVertices();
result.print();
env.execute("Gelly Connected Components");
{% endhighlight %}
Notice that when assigning the initial vertex IDs, there is no need to perform a separate map operation. The value is specified directly in the `fromDataSet()` method.
-Instead of calling `runOperation()` on the set of vertices, `runVertexCentricIteration()` is called on the graph instance.
-As previously stated, `runVertexCentricIteration` returns a new graph with the updated vertex values. In order to retrieve the result (since for this algorithm we are only interested in the vertex ids and their corresponding values), we will call the `getVertices()` method.
+Instead of calling `runOperation()` on the set of vertices, `runVertexCentricIteration()` is called on the `Graph` instance.
+As previously stated, `runVertexCentricIteration` returns a new `Graph` with the updated vertex values. In order to retrieve the result (since for this algorithm we are only interested in the vertex ids and their corresponding values), we will call the `getVertices()` method.
+
+The user-defined `VertexUpdateFunction` and `MessagingFunction` remain unchanged in Gelly, so you can reuse them without any changes.
-In the connected components algorithm, the vertices propagate their current component ID in iterations, each time adopting a new value from the received neighbor IDs, provided that the value is smaller than the current minimum.
+In the Connected Components algorithm, the vertices propagate their current component ID in iterations, each time adopting a new value from the received neighbor IDs, provided that the value is smaller than the current minimum.
To this end, we iterate over all received messages and update the vertex value, if necessary:
{% highlight java %}
@@ -533,69 +594,16 @@ public static final class CCMessenger extends MessagingFunction<Long, Long, Long
}
{% endhighlight %}
-The fact that the two names for the `VertexUpdateFunction` and for the `MessagingFunction`: `CCUpdater` and `CCMessenger` coincide in Spargel's `runOperation()` and in Gelly's `runVertexCentricIteration()` implies that the classes defined for the Spargel algortihm remain unchanged in Gelly.
Similarly to Spargel, if the value of a vertex does not change during a superstep, it will **not send** any messages in the superstep. This allows to do incremental updates to the **hot (changing) parts** of the graph, while leaving **cold (steady) parts** untouched.
The computation **terminates** after a specified *maximum number of supersteps* **-OR-** when the *vertex states stop changing*.
<p class="text-center">
- <img alt="Spargel Example" width="75%" src="img/spargel_example.png" />
+ <img alt="Spargel Example" width="75%" src="fig/spargel_example.png" />
</p>
[Back to top](#top)
-Graph Validation
------------
-
-Gelly provides a simple utility for performing validation checks on input graphs. Depending on the application context, a graph may or may not be valid according to certain criteria. For example, a user might need to validate whether their graph contains duplicate edges or whether its structure is bipartite. In order to validate a graph, one can define a custom `GraphValidator` and implement its `validate()` method. `InvalidVertexIdsValidator` is Gelly's pre-defined validator. It checks that the edge set contains valid vertex IDs, i.e. that all edge IDs
-also exist in the vertex IDs set.
-
-{% highlight java %}
-ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-
-// create a list of vertices with IDs = {1, 2, 3, 4, 5}
-List<Vertex<Long, Long>> vertices = ...
-
-// create a list of edges with IDs = {(1, 2) (1, 3), (2, 4), (5, 6)}
-List<Edge<Long, Long>> edges = ...
-
-Graph<Long, Long, Long> graph = Graph.fromCollection(vertices, edges, env);
-
-// will return false: 6 is an invalid ID
-graph.validate(new InvalidVertexIdsValidator<Long, Long, Long>());
-
-{% endhighlight %}
-
-[Back to top](#top)
-
-Library Methods
------------
-Gelly has a growing collection of graph algorithms for easily analyzing large-scale Graphs. So far, the following library methods are implemented:
-
-* PageRank
-* Single-Source Shortest Paths
-* Label Propagation
-* Simple Community Detection
-* Connected Components
-
-Gelly's library methods can be used by simply calling the `run()` method on the input graph:
-
-{% highlight java %}
-ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-
-Graph<Long, Long, NullValue> graph = ...
-
-// run Label Propagation for 30 iterations to detect communities on the input graph
-DataSet<Vertex<Long, Long>> verticesWithCommunity = graph.run(
- new LabelPropagation<Long>(30)).getVertices();
-
-// print the result
-verticesWithCommunity.print();
-
-env.execute();
-{% endhighlight %}
-
-[Back to top](#top)
http://git-wip-us.apache.org/repos/asf/flink/blob/60ec6830/docs/libs/spargel_guide.md
----------------------------------------------------------------------
diff --git a/docs/libs/spargel_guide.md b/docs/libs/spargel_guide.md
index 108b8f7..ab69783 100644
--- a/docs/libs/spargel_guide.md
+++ b/docs/libs/spargel_guide.md
@@ -32,8 +32,10 @@ This vertex-centric view makes it easy to express a large class of graph problem
* This will be replaced by the TOC
{:toc}
-Spargel API - DEPRECATED (Please check out new [Gelly API](gelly_guide.html) for graph processing with Apache Flink)
+Spargel API - DEPRECATED
-----------
+The Spargel API is Deprecated. Please check out the new [Gelly API](gelly_guide.html) for graph processing with Apache Flink. If you want to port your Spargel code into Gelly,
+please check the [migration guide](gelly_guide.html#migrating-spargel-code-to-gelly).
The Spargel API is part of the *addons* Maven project. All relevant classes are located in the *org.apache.flink.spargel.java* package.
http://git-wip-us.apache.org/repos/asf/flink/blob/60ec6830/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/ConnectedComponentsExample.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/ConnectedComponentsExample.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/ConnectedComponentsExample.java
index 63265b6..a185a70 100644
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/ConnectedComponentsExample.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/ConnectedComponentsExample.java
@@ -119,6 +119,7 @@ public class ConnectedComponentsExample implements ProgramDescription {
return true;
}
+ @SuppressWarnings("serial")
private static DataSet<Edge<Long, NullValue>> getEdgesDataSet(ExecutionEnvironment env) {
if(fileOutput) {
http://git-wip-us.apache.org/repos/asf/flink/blob/60ec6830/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
index b6f0c87..b27a8fb 100644
--- a/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
+++ b/flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/GSAPageRank.java
@@ -45,6 +45,7 @@ import org.apache.flink.util.Collector;
*/
public class GSAPageRank implements ProgramDescription {
+ @SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
if(!parseParameters(args)) {