Search in sources :

Example 6 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testAllInNeighborsNoValue.

@Test
public void testAllInNeighborsNoValue() throws Exception {
    /*
		 * Get the all the in-neighbors for each vertex except for the vertex with id 5.
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithAllInNeighbors = graph.groupReduceOnEdges(new SelectInNeighborsExceptFive(), EdgeDirection.IN);
    List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect();
    expectedResult = "1,5\n" + "2,1\n" + "3,1\n" + "3,2\n" + "4,3";
    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 7 with Tuple2

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

the class ReduceOnEdgesWithExceptionITCase method testGroupReduceOnEdgesInvalidEdgeSrcId.

/**
	 * Test groupReduceOnEdges() with an edge having a srcId that does not exist in the vertex DataSet
	 */
@Test
public void testGroupReduceOnEdgesInvalidEdgeSrcId() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment("localhost", cluster.getLeaderRPCPort());
    env.setParallelism(PARALLELISM);
    env.getConfig().disableSysoutLogging();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env);
    try {
        DataSet<Tuple2<Long, Long>> verticesWithAllNeighbors = graph.groupReduceOnEdges(new SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL);
        verticesWithAllNeighbors.output(new DiscardingOutputFormat<Tuple2<Long, Long>>());
        env.execute();
    } catch (Exception e) {
    // We expect the job to fail with an exception
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 8 with Tuple2

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

the class ReduceOnNeighborMethodsITCase method testSumOfOutNeighbors.

@Test
public void testSumOfOutNeighbors() 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.groupReduceOnNeighbors(new SumOutNeighbors(), 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 9 with Tuple2

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

the class ReduceOnNeighborMethodsITCase method testSumOfOutNeighborsNoValueMultipliedByTwoIdGreaterThanTwo.

@Test
public void testSumOfOutNeighborsNoValueMultipliedByTwoIdGreaterThanTwo() throws Exception {
    /*
		 * Get the sum of out-neighbor values
		 * for each vertex with id greater than two as well as the same sum multiplied by two.
         */
    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 SumOutNeighborsNoValueMultipliedByTwoIdGreaterThanTwo(), EdgeDirection.OUT);
    List<Tuple2<Long, Long>> result = verticesWithSumOfOutNeighborValues.collect();
    expectedResult = "3,9\n" + "3,18\n" + "4,5\n" + "4,10\n" + "5,1\n" + "5,2";
    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 10 with Tuple2

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

the class ReduceOnNeighborMethodsITCase method testSumOfInNeighborsIdGreaterThanThree.

@Test
public void testSumOfInNeighborsIdGreaterThanThree() throws Exception {
    /*
		 * Get the sum of in-neighbor values
		 * times the edge weights 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>> verticesWithSum = graph.groupReduceOnNeighbors(new SumInNeighborsIdGreaterThanThree(), EdgeDirection.IN);
    List<Tuple2<Long, Long>> result = verticesWithSum.collect();
    expectedResult = "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