Search in sources :

Example 41 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class JoinWithEdgesITCase method testWithLessElements.

@Test
public void testWithLessElements() throws Exception {
    /*
         * Test joinWithEdges with the input DataSet passed as a parameter containing
         * less elements than the edge DataSet, but of the same type
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdges(graph.getEdges().first(3).map(new EdgeToTuple3Map<>()), new AddValuesMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,46\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) EdgeToTuple3Map(org.apache.flink.graph.utils.EdgeToTuple3Map) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 42 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class JoinWithEdgesITCase method testWithEdgesOnSource.

@Test
public void testWithEdgesOnSource() throws Exception {
    /*
         * Test joinWithEdgesOnSource with the input DataSet parameter identical
         * to the edge DataSet
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdgesOnSource(graph.getEdges().map(new ProjectSourceAndValueMapper()), new AddValuesMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,25\n" + "2,3,46\n" + "3,4,68\n" + "3,5,69\n" + "4,5,90\n" + "5,1,102\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 43 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class JoinWithEdgesITCase method testWithCustomType.

@Test
public void testWithCustomType() throws Exception {
    /*
         * Test joinWithEdges with a DataSet containing custom parametrised type input values
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    Graph<Long, Long, Long> res = graph.joinWithEdges(TestGraphUtils.getLongLongCustomTuple3Data(env), new CustomValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,10\n" + "1,3,20\n" + "2,3,30\n" + "3,4,40\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 44 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class PageRank method runInternal.

@Override
public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception {
    // vertex degree
    DataSet<Vertex<K, Degrees>> vertexDegree = input.run(new VertexDegrees<K, VV, EV>().setParallelism(parallelism));
    // vertex count
    DataSet<LongValue> vertexCount = GraphUtils.count(vertexDegree);
    // s, t, d(s)
    DataSet<Edge<K, LongValue>> edgeSourceDegree = input.run(new EdgeSourceDegrees<K, VV, EV>().setParallelism(parallelism)).map(new ExtractSourceDegree<K, EV>()).setParallelism(parallelism).name("Extract source degree");
    // vertices with zero in-edges
    DataSet<Tuple2<K, DoubleValue>> sourceVertices = vertexDegree.flatMap(new InitializeSourceVertices<K>()).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Initialize source vertex scores");
    // s, initial pagerank(s)
    DataSet<Tuple2<K, DoubleValue>> initialScores = vertexDegree.map(new InitializeVertexScores<K>()).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Initialize scores");
    IterativeDataSet<Tuple2<K, DoubleValue>> iterative = initialScores.iterate(maxIterations);
    // s, projected pagerank(s)
    DataSet<Tuple2<K, DoubleValue>> vertexScores = iterative.coGroup(edgeSourceDegree).where(0).equalTo(0).with(new SendScore<K>()).setParallelism(parallelism).name("Send score").groupBy(0).reduce(new SumScore<K>()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    // ignored ID, total pagerank
    DataSet<Tuple2<K, DoubleValue>> sumOfScores = vertexScores.reduce(new SumVertexScores<K>()).setParallelism(parallelism).name("Sum");
    // s, adjusted pagerank(s)
    DataSet<Tuple2<K, DoubleValue>> adjustedScores = vertexScores.union(sourceVertices).setParallelism(parallelism).name("Union with source vertices").map(new AdjustScores<K>(dampingFactor)).withBroadcastSet(sumOfScores, SUM_OF_SCORES).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Adjust scores");
    DataSet<Tuple2<K, DoubleValue>> passThrough;
    if (convergenceThreshold < Double.MAX_VALUE) {
        passThrough = iterative.join(adjustedScores).where(0).equalTo(0).with(new ChangeInScores<K>()).setParallelism(parallelism).name("Change in scores");
        iterative.registerAggregationConvergenceCriterion(CHANGE_IN_SCORES, new DoubleSumAggregator(), new ScoreConvergence(convergenceThreshold));
    } else {
        passThrough = adjustedScores;
    }
    return iterative.closeWith(passThrough).map(new TranslateResult<K>()).setParallelism(parallelism).name("Map result");
}
Also used : Vertex(org.apache.flink.graph.Vertex) DoubleSumAggregator(org.apache.flink.api.common.aggregators.DoubleSumAggregator) SumScore(org.apache.flink.graph.library.link_analysis.Functions.SumScore) VertexDegrees(org.apache.flink.graph.asm.degree.annotate.directed.VertexDegrees) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) Edge(org.apache.flink.graph.Edge)

Example 45 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class SimplifyTest method setup.

@Before
public void setup() {
    ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();
    Object[][] edges = new Object[][] { new Object[] { 0, 0 }, new Object[] { 0, 1 }, new Object[] { 0, 1 }, new Object[] { 0, 2 }, new Object[] { 0, 2 }, new Object[] { 1, 0 }, new Object[] { 2, 2 } };
    List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>();
    for (Object[] edge : edges) {
        edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance()));
    }
    graph = Graph.fromCollection(edgeList, env);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) IntValue(org.apache.flink.types.IntValue) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Aggregations

Edge (org.apache.flink.graph.Edge)87 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)72 Test (org.junit.Test)69 Vertex (org.apache.flink.graph.Vertex)46 NullValue (org.apache.flink.types.NullValue)20 LongValue (org.apache.flink.types.LongValue)16 ArrayList (java.util.ArrayList)14 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)12 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)7 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)7 Plan (org.apache.flink.api.common.Plan)6 FieldList (org.apache.flink.api.common.operators.util.FieldList)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)6 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)6 PlanNode (org.apache.flink.optimizer.plan.PlanNode)6 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)6 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)6 LinkedList (java.util.LinkedList)5 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)5