@SuppressWarnings("serial")
  public static void main(String[] args) throws Exception {

    if (!parseParameters(args)) {
      return;
    }

    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataSet<Edge<Long, NullValue>> edges = getEdgesDataSet(env);

    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>> verticesWithMinIds =
        graph.run(new GSAConnectedComponents<Long, Long, NullValue>(maxIterations));

    // emit result
    if (fileOutput) {
      verticesWithMinIds.writeAsCsv(outputPath, "\n", ",");

      // since file sinks are lazy, we trigger the execution explicitly
      env.execute("Connected Components Example");
    } else {
      verticesWithMinIds.print();
    }
  }
Beispiel #2
0
  @Override
  public VertexMetrics<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception {
    super.run(input);

    DataSet<Vertex<K, Degrees>> vertexDegree =
        input.run(
            new VertexDegrees<K, VV, EV>()
                .setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
                .setParallelism(parallelism));

    vertexDegree.output(new VertexMetricsHelper<K>(id)).name("Vertex metrics");

    return this;
  }
Beispiel #3
0
  @Override
  public DataSet<Edge<K, Tuple2<EV, LongValue>>> run(Graph<K, VV, EV> input) throws Exception {
    // t, d(t)
    DataSet<Vertex<K, LongValue>> vertexDegrees =
        input.run(
            new VertexDegree<K, VV, EV>()
                .setReduceOnTargetId(!reduceOnSourceId)
                .setParallelism(parallelism));

    // s, t, d(t)
    return input
        .getEdges()
        .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND)
        .where(1)
        .equalTo(0)
        .with(new JoinEdgeWithVertexDegree<K, EV>())
        .setParallelism(parallelism)
        .name("Edge target degree");
  }