Search in sources :

Example 21 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testLowestWeightOutNeighbor.

@Test
public void testLowestWeightOutNeighbor() throws Exception {
    /*
		 * Get the lowest-weight out-neighbor
		 * 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>> verticesWithLowestOutNeighbor = graph.groupReduceOnEdges(new SelectMinWeightNeighbor(), EdgeDirection.OUT);
    List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect();
    expectedResult = "1,2\n" + "2,3\n" + "3,4\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 22 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testAllInNeighborsWithValueGreaterThanTwo.

@Test
public void testAllInNeighborsWithValueGreaterThanTwo() throws Exception {
    /*
		 * Get the all the in-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>> verticesWithAllInNeighbors = graph.groupReduceOnEdges(new SelectInNeighborsValueGreaterThanTwo(), EdgeDirection.IN);
    List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect();
    expectedResult = "3,1\n" + "3,2\n" + "4,3\n" + "5,3\n" + "5,4";
    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 23 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testMaxWeightEdge.

@Test
public void testMaxWeightEdge() throws Exception {
    /*
		 * Get the maximum weight among all edges
		 * of a vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Tuple2<Long, Long>> verticesWithMaxEdgeWeight = graph.groupReduceOnEdges(new SelectMaxWeightNeighbor(), EdgeDirection.ALL);
    List<Tuple2<Long, Long>> result = verticesWithMaxEdgeWeight.collect();
    expectedResult = "1,51\n" + "2,23\n" + "3,35\n" + "4,45\n" + "5,51\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 24 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testLowestWeightOutNeighborNoValue.

@Test
public void testLowestWeightOutNeighborNoValue() throws Exception {
    /*
		 * Get the lowest-weight out of all the out-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.OUT);
    List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect();
    expectedResult = "1,12\n" + "2,23\n" + "3,34\n" + "4,45\n" + "5,51\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 25 with Tuple2

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

the class ReduceOnEdgesMethodsITCase method testAllNeighborsNoValue.

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