Search in sources :

Example 16 with Tuple2

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

the class ReduceOnNeighborMethodsITCase method testSumOfAllNeighborsNoValue.

@Test
public void testSumOfAllNeighborsNoValue() throws Exception {
    /*
		 * Get the sum of all 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>> verticesWithSumOfAllNeighborValues = graph.reduceOnNeighbors(new SumNeighbors(), EdgeDirection.ALL);
    List<Tuple2<Long, Long>> result = verticesWithSumOfAllNeighborValues.collect();
    expectedResult = "1,10\n" + "2,4\n" + "3,12\n" + "4,8\n" + "5,8\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 17 with Tuple2

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

the class ReduceOnNeighborsWithExceptionITCase method testGroupReduceOnNeighborsInvalidEdgeSrcId.

/**
	 * Test groupReduceOnNeighbors() -NeighborsFunction-
	 * with an edge having a srcId that does not exist in the vertex DataSet
	 */
@Test
public void testGroupReduceOnNeighborsInvalidEdgeSrcId() 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.getLongLongEdgeInvalidTrgData(env), env);
    try {
        DataSet<Tuple2<Long, Long>> verticesWithSumOfAllNeighborValues = graph.reduceOnNeighbors(new SumNeighbors(), EdgeDirection.ALL);
        verticesWithSumOfAllNeighborValues.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 18 with Tuple2

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

the class ReduceOnNeighborsWithExceptionITCase method testGroupReduceOnNeighborsWithVVInvalidEdgeTrgId.

/**
	 * Test groupReduceOnNeighbors() -NeighborsFunctionWithVertexValue-
	 * with an edge having a trgId that does not exist in the vertex DataSet
	 */
@Test
public void testGroupReduceOnNeighborsWithVVInvalidEdgeTrgId() 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.getLongLongEdgeInvalidTrgData(env), env);
    try {
        DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues = graph.groupReduceOnNeighbors(new SumAllNeighbors(), EdgeDirection.ALL);
        verticesWithSumOfOutNeighborValues.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 19 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testAllOutNeighborsWithValueGreaterThanTwo.

@Test
public void testAllOutNeighborsWithValueGreaterThanTwo() throws Exception {
    /*
		 * Get the all the out-neighbors for each vertex that have a value greater than two.
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithAllOutNeighbors = graph.groupReduceOnEdges(new SelectOutNeighborsValueGreaterThanTwo(), EdgeDirection.OUT);
    List<Tuple2<Long, Long>> result = verticesWithAllOutNeighbors.collect();
    expectedResult = "3,4\n" + "3,5\n" + "4,5\n" + "5,1";
    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 20 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testLowestWeightInNeighborNoValue.

@Test
public void testLowestWeightInNeighborNoValue() throws Exception {
    /*
		 * Get the lowest-weight out of all the in-neighbors
		 * of 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>> verticesWithLowestOutNeighbor = graph.reduceOnEdges(new SelectMinWeightNeighborNoValue(), EdgeDirection.IN);
    List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect();
    expectedResult = "1,51\n" + "2,12\n" + "3,13\n" + "4,34\n" + "5,35\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