Github user vasia commented on a diff in the pull request:
https://github.com/apache/flink/pull/770#discussion_r32374939
--- Diff:
flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/JaccardSimilarityMeasure.java
---
@@ -66,34 +63,47 @@ public static void main(String [] args) throws
Exception {
DataSet<Edge<Long, Double>> edges = getEdgesDataSet(env);
- Graph<Long, NullValue, Double> graph = Graph.fromDataSet(edges,
env);
+ Graph<Long, HashSet<Long>, Double> graph =
Graph.fromDataSet(edges,
+ new MapFunction<Long, HashSet<Long>>() {
- DataSet<Vertex<Long, HashSet<Long>>> verticesWithNeighbors =
- graph.groupReduceOnEdges(new GatherNeighbors(),
EdgeDirection.ALL);
+ @Override
+ public HashSet<Long> map(Long id)
throws Exception {
+ HashSet<Long> neighbors = new
HashSet<Long>();
+ neighbors.add(id);
- Graph<Long, HashSet<Long>, Double> graphWithVertexValues =
Graph.fromDataSet(verticesWithNeighbors, edges, env);
+ return new
HashSet<Long>(neighbors);
+ }
+ }, env);
- // the edge value will be the Jaccard similarity
coefficient(number of common neighbors/ all neighbors)
- DataSet<Tuple3<Long, Long, Double>> edgesWithJaccardWeight =
graphWithVertexValues.getTriplets()
- .map(new WeighEdgesMapper());
+ // create the set of neighbors
+ DataSet<Tuple2<Long, HashSet<Long>>> computedNeighbors =
+ graph.reduceOnNeighbors(new GatherNeighbors(),
EdgeDirection.ALL);
- DataSet<Edge<Long, Double>> result =
graphWithVertexValues.joinWithEdges(edgesWithJaccardWeight,
- new MapFunction<Tuple2<Double, Double>,
Double>() {
+ // join with the vertices to update the node values
+ DataSet<Vertex<Long, HashSet<Long>>> verticesWithNeighbors =
+ graph.joinWithVertices(computedNeighbors, new
MapFunction<Tuple2<HashSet<Long>, HashSet<Long>>,
+ HashSet<Long>>() {
@Override
- public Double map(Tuple2<Double,
Double> value) throws Exception {
- return value.f1;
+ public HashSet<Long>
map(Tuple2<HashSet<Long>, HashSet<Long>> tuple2) throws Exception {
+ return tuple2.f1;
}
- }).getEdges();
+ }).getVertices();
+
+ Graph<Long, HashSet<Long>, Double> graphWithVertexValues =
Graph.fromDataSet(verticesWithNeighbors, edges, env);
--- End diff --
joinWithVertices can give you the Graph directly :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---