Search in sources :

Example 96 with Edge

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

the class GSATranslationTest method testTranslation.

@Test
public void testTranslation() {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Long> bcGather = env.fromElements(1L);
    DataSet<Long> bcSum = env.fromElements(1L);
    DataSet<Long> bcApply = env.fromElements(1L);
    DataSet<Vertex<Long, Long>> result;
    // ------------ construct the test program ------------------
    DataSet<Edge<Long, NullValue>> edges = env.fromElements(new Tuple3<>(1L, 2L, NullValue.getInstance())).map(new Tuple3ToEdgeMap<>());
    Graph<Long, Long, NullValue> graph = Graph.fromDataSet(edges, new InitVertices(), env);
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.registerAggregator(AGGREGATOR_NAME, new LongSumAggregator());
    parameters.setName(ITERATION_NAME);
    parameters.setParallelism(ITERATION_parallelism);
    parameters.addBroadcastSetForGatherFunction(BC_SET_GATHER_NAME, bcGather);
    parameters.addBroadcastSetForSumFunction(BC_SET_SUM_NAME, bcSum);
    parameters.addBroadcastSetForApplyFunction(BC_SET_APLLY_NAME, bcApply);
    result = graph.runGatherSumApplyIteration(new GatherNeighborIds(), new SelectMinId(), new UpdateComponentId(), NUM_ITERATIONS, parameters).getVertices();
    result.output(new DiscardingOutputFormat<>());
    // ------------- validate the java program ----------------
    assertTrue(result instanceof DeltaIterationResultSet);
    DeltaIterationResultSet<?, ?> resultSet = (DeltaIterationResultSet<?, ?>) result;
    DeltaIteration<?, ?> iteration = resultSet.getIterationHead();
    // check the basic iteration properties
    assertEquals(NUM_ITERATIONS, resultSet.getMaxIterations());
    assertArrayEquals(new int[] { 0 }, resultSet.getKeyPositions());
    assertEquals(ITERATION_parallelism, iteration.getParallelism());
    assertEquals(ITERATION_NAME, iteration.getName());
    assertEquals(AGGREGATOR_NAME, iteration.getAggregators().getAllRegisteredAggregators().iterator().next().getName());
    // validate that the semantic properties are set as they should
    TwoInputUdfOperator<?, ?, ?, ?> solutionSetJoin = (TwoInputUdfOperator<?, ?, ?, ?>) resultSet.getNextWorkset();
    assertTrue(solutionSetJoin.getSemanticProperties().getForwardingTargetFields(0, 0).contains(0));
    assertTrue(solutionSetJoin.getSemanticProperties().getForwardingTargetFields(1, 0).contains(0));
    SingleInputUdfOperator<?, ?, ?> sumReduce = (SingleInputUdfOperator<?, ?, ?>) solutionSetJoin.getInput1();
    SingleInputUdfOperator<?, ?, ?> gatherMap = (SingleInputUdfOperator<?, ?, ?>) sumReduce.getInput();
    // validate that the broadcast sets are forwarded
    assertEquals(bcGather, gatherMap.getBroadcastSets().get(BC_SET_GATHER_NAME));
    assertEquals(bcSum, sumReduce.getBroadcastSets().get(BC_SET_SUM_NAME));
    assertEquals(bcApply, solutionSetJoin.getBroadcastSets().get(BC_SET_APLLY_NAME));
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) LongSumAggregator(org.apache.flink.api.common.aggregators.LongSumAggregator) DeltaIterationResultSet(org.apache.flink.api.java.operators.DeltaIterationResultSet) TwoInputUdfOperator(org.apache.flink.api.java.operators.TwoInputUdfOperator) NullValue(org.apache.flink.types.NullValue) SingleInputUdfOperator(org.apache.flink.api.java.operators.SingleInputUdfOperator) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 97 with Edge

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

the class EdgeDegreePairTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Edge<LongValue, Tuple3<NullValue, LongValue, LongValue>>> degreePairOnSourceId = undirectedRMatGraph(10, 16).run(new EdgeDegreePair<LongValue, NullValue, NullValue>().setReduceOnTargetId(false));
    Checksum checksumOnSourceId = new ChecksumHashCode<Edge<LongValue, Tuple3<NullValue, LongValue, LongValue>>>().run(degreePairOnSourceId).execute();
    assertEquals(20884, checksumOnSourceId.getCount());
    assertEquals(0x00000001e051efe4L, checksumOnSourceId.getChecksum());
    DataSet<Edge<LongValue, Tuple3<NullValue, LongValue, LongValue>>> degreePairOnTargetId = undirectedRMatGraph(10, 16).run(new EdgeDegreePair<LongValue, NullValue, NullValue>().setReduceOnTargetId(true));
    Checksum checksumOnTargetId = new ChecksumHashCode<Edge<LongValue, Tuple3<NullValue, LongValue, LongValue>>>().run(degreePairOnTargetId).execute();
    assertEquals(checksumOnSourceId, checksumOnTargetId);
}
Also used : NullValue(org.apache.flink.types.NullValue) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) Tuple3(org.apache.flink.api.java.tuple.Tuple3) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 98 with Edge

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

the class EdgeTargetDegreeTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnTargetId = undirectedRMatGraph(10, 16).run(new EdgeTargetDegree<LongValue, NullValue, NullValue>().setReduceOnSourceId(false));
    Checksum checksumOnTargetId = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, LongValue>>>().run(targetDegreeOnTargetId).execute();
    assertEquals(20884, checksumOnTargetId.getCount());
    assertEquals(0x000000019d8f0070L, checksumOnTargetId.getChecksum());
    DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnSourceId = undirectedRMatGraph(10, 16).run(new EdgeTargetDegree<LongValue, NullValue, NullValue>().setReduceOnSourceId(true));
    Checksum checksumOnSourceId = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, LongValue>>>().run(targetDegreeOnSourceId).execute();
    assertEquals(checksumOnTargetId, checksumOnSourceId);
}
Also used : NullValue(org.apache.flink.types.NullValue) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 99 with Edge

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

the class EdgeDegreesPairTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Edge<LongValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedRMatGraph(10, 16).run(new EdgeDegreesPair<>());
    Checksum checksum = new ChecksumHashCode<Edge<LongValue, Tuple3<NullValue, Degrees, Degrees>>>().run(degreesPair).execute();
    assertEquals(12009, checksum.getCount());
    assertEquals(0x0000176fe94702a3L, checksum.getChecksum());
}
Also used : NullValue(org.apache.flink.types.NullValue) Degrees(org.apache.flink.graph.asm.degree.annotate.directed.VertexDegrees.Degrees) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) Tuple3(org.apache.flink.api.java.tuple.Tuple3) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 100 with Edge

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

the class EdgeSourceDegreesTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Edge<LongValue, Tuple2<NullValue, Degrees>>> sourceDegrees = directedRMatGraph(10, 16).run(new EdgeSourceDegrees<>());
    Checksum checksum = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, Degrees>>>().run(sourceDegrees).execute();
    assertEquals(12009, checksum.getCount());
    assertEquals(0x0000162435fde1d9L, checksum.getChecksum());
}
Also used : NullValue(org.apache.flink.types.NullValue) Degrees(org.apache.flink.graph.asm.degree.annotate.directed.VertexDegrees.Degrees) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)251 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)210 Test (org.junit.Test)207 Vertex (org.apache.flink.graph.Vertex)132 NullValue (org.apache.flink.types.NullValue)58 LongValue (org.apache.flink.types.LongValue)44 ArrayList (java.util.ArrayList)42 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)34 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)21 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)21 Plan (org.apache.flink.api.common.Plan)18 FieldList (org.apache.flink.api.common.operators.util.FieldList)18 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)18 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)18 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)18 PlanNode (org.apache.flink.optimizer.plan.PlanNode)18 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)18 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)18 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)13 FilterFunction (org.apache.flink.api.common.functions.FilterFunction)12