Search in sources :

Example 11 with Tuple2

use of org.apache.flink.api.java.tuple.Tuple2 in project flink by apache.

the class ReduceOnNeighborMethodsITCase method testSumOfOutNeighborsIdGreaterThanThree.

@Test
public void testSumOfOutNeighborsIdGreaterThanThree() throws Exception {
    /*
		 * Get the sum of out-neighbor values
		 * for each vertex with id greater than three.
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues = graph.groupReduceOnNeighbors(new SumOutNeighborsIdGreaterThanThree(), EdgeDirection.OUT);
    List<Tuple2<Long, Long>> result = verticesWithSumOfOutNeighborValues.collect();
    expectedResult = "4,5\n" + "5,1\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 12 with Tuple2

use of org.apache.flink.api.java.tuple.Tuple2 in project flink by apache.

the class ReduceOnNeighborMethodsITCase method testSumOfOAllNeighborsAddFive.

@Test
public void testSumOfOAllNeighborsAddFive() throws Exception {
    /*
		 * Get the sum of all neighbor values
		 * including own vertex value
		 * for each vertex as well as the same sum plus five.
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues = graph.groupReduceOnNeighbors(new SumAllNeighborsAddFive(), EdgeDirection.ALL);
    List<Tuple2<Long, Long>> result = verticesWithSumOfOutNeighborValues.collect();
    expectedResult = "1,11\n" + "1,16\n" + "2,6\n" + "2,11\n" + "3,15\n" + "3,20\n" + "4,12\n" + "4,17\n" + "5,13\n" + "5,18";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 13 with Tuple2

use of org.apache.flink.api.java.tuple.Tuple2 in project flink by apache.

the class ReduceOnNeighborMethodsITCase method testSumOfOutNeighborsNoValue.

@Test
public void testSumOfOutNeighborsNoValue() throws Exception {
    /*
		 * Get the sum of out-neighbor values
		 * for each vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues = graph.reduceOnNeighbors(new SumNeighbors(), EdgeDirection.OUT);
    List<Tuple2<Long, Long>> result = verticesWithSumOfOutNeighborValues.collect();
    expectedResult = "1,5\n" + "2,3\n" + "3,9\n" + "4,5\n" + "5,1\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 14 with Tuple2

use of org.apache.flink.api.java.tuple.Tuple2 in project flink by apache.

the class ReduceOnNeighborMethodsITCase method testSumOfOAllNeighbors.

@Test
public void testSumOfOAllNeighbors() throws Exception {
    /*
		 * Get the sum of all neighbor values
		 * including own vertex value
		 * for each vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues = graph.groupReduceOnNeighbors(new SumAllNeighbors(), EdgeDirection.ALL);
    List<Tuple2<Long, Long>> result = verticesWithSumOfOutNeighborValues.collect();
    expectedResult = "1,11\n" + "2,6\n" + "3,15\n" + "4,12\n" + "5,13\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 15 with Tuple2

use of org.apache.flink.api.java.tuple.Tuple2 in project flink by apache.

the class ReduceOnNeighborMethodsITCase method testSumOfInNeighbors.

@Test
public void testSumOfInNeighbors() throws Exception {
    /*
		 * Get the sum of in-neighbor values
		 * times the edge weights for each vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithSum = graph.groupReduceOnNeighbors(new SumInNeighbors(), EdgeDirection.IN);
    List<Tuple2<Long, Long>> result = verticesWithSum.collect();
    expectedResult = "1,255\n" + "2,12\n" + "3,59\n" + "4,102\n" + "5,285\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)813 Test (org.junit.Test)643 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)373 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)192 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)130 Plan (org.apache.flink.api.common.Plan)100 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)99 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)96 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)81 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)72 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)65 ArrayList (java.util.ArrayList)54 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)52 TestData (org.apache.flink.runtime.operators.testutils.TestData)51 KeyedOneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)44 EventTimeTrigger (org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger)42 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)40 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)38 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)38 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)37