Java Code Examples for org.apache.flink.graph.Graph#groupReduceOnEdges()
The following examples show how to use
org.apache.flink.graph.Graph#groupReduceOnEdges() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReduceOnEdgesWithExceptionITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Test groupReduceOnEdges() with an edge having a trgId that does not exist in the vertex DataSet. */ @Test public void testGroupReduceOnEdgesInvalidEdgeTrgId() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); 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>> verticesWithAllNeighbors = graph.groupReduceOnEdges(new SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL); verticesWithAllNeighbors.output(new DiscardingOutputFormat<>()); env.execute(); fail("Expected an exception."); } catch (Exception e) { // We expect the job to fail with an exception } }
Example 2
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAllOutNeighborsNoValue() throws Exception { /* * Get the all the out-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>> verticesWithAllOutNeighbors = graph.groupReduceOnEdges(new SelectOutNeighborsExcludeFive(), EdgeDirection.OUT); List<Tuple2<Long, Long>> result = verticesWithAllOutNeighbors.collect(); expectedResult = "1,2\n" + "1,3\n" + "2,3\n" + "3,4\n" + "3,5\n" + "4,5"; compareResultAsTuples(result, expectedResult); }
Example 3
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAllOutNeighbors() throws Exception { /* * Get the all the out-neighbors 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>> verticesWithAllOutNeighbors = graph.groupReduceOnEdges(new SelectOutNeighbors(), EdgeDirection.OUT); List<Tuple2<Long, Long>> result = verticesWithAllOutNeighbors.collect(); expectedResult = "1,2\n" + "1,3\n" + "2,3\n" + "3,4\n" + "3,5\n" + "4,5\n" + "5,1"; compareResultAsTuples(result, expectedResult); }
Example 4
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 7
Source File: ReduceOnEdgesWithExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
/** * 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.getExecutionEnvironment(); 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<>()); env.execute(); fail("Expected an exception."); } catch (Exception e) { // We expect the job to fail with an exception } }
Example 8
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 9
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 10
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAllNeighborsWithValueGreaterThanFour() throws Exception { /* * Get the all the neighbors for each vertex that have a value greater than four. */ 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 SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL); List<Tuple2<Long, Long>> result = verticesWithAllNeighbors.collect(); expectedResult = "5,1\n" + "5,3\n" + "5,4"; compareResultAsTuples(result, expectedResult); }
Example 11
Source File: ReduceOnEdgesMethodsITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example 12
Source File: ReduceOnEdgesMethodsITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example 13
Source File: ReduceOnEdgesMethodsITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testAllInNeighbors() throws Exception { /* * Get the all the in-neighbors 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>> verticesWithAllInNeighbors = graph.groupReduceOnEdges(new SelectInNeighbors(), EdgeDirection.IN); List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect(); expectedResult = "1,5\n" + "2,1\n" + "3,1\n" + "3,2\n" + "4,3\n" + "5,3\n" + "5,4"; compareResultAsTuples(result, expectedResult); }
Example 14
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testLowestWeightInNeighbor() throws Exception { /* * Get the lowest-weight in-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 SelectMinWeightInNeighbor(), EdgeDirection.IN); List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect(); expectedResult = "1,5\n" + "2,1\n" + "3,1\n" + "4,3\n" + "5,3\n"; compareResultAsTuples(result, expectedResult); }
Example 15
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAllNeighborsWithValueGreaterThanFour() throws Exception { /* * Get the all the neighbors for each vertex that have a value greater than four. */ 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 SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL); List<Tuple2<Long, Long>> result = verticesWithAllNeighbors.collect(); expectedResult = "5,1\n" + "5,3\n" + "5,4"; compareResultAsTuples(result, expectedResult); }
Example 16
Source File: ReduceOnEdgesWithExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
/** * Test groupReduceOnEdges() with an edge having a trgId that does not exist in the vertex DataSet. */ @Test public void testGroupReduceOnEdgesInvalidEdgeTrgId() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(PARALLELISM); Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env); try { DataSet<Tuple2<Long, Long>> verticesWithAllNeighbors = graph.groupReduceOnEdges(new SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL); verticesWithAllNeighbors.output(new DiscardingOutputFormat<>()); env.execute(); fail("Expected an exception."); } catch (Exception e) { // We expect the job to fail with an exception } }
Example 17
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAllInNeighbors() throws Exception { /* * Get the all the in-neighbors 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>> verticesWithAllInNeighbors = graph.groupReduceOnEdges(new SelectInNeighbors(), EdgeDirection.IN); List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect(); expectedResult = "1,5\n" + "2,1\n" + "3,1\n" + "3,2\n" + "4,3\n" + "5,3\n" + "5,4"; compareResultAsTuples(result, expectedResult); }
Example 18
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 19
Source File: ReduceOnEdgesMethodsITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 20
Source File: ReduceOnEdgesMethodsITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testAllNeighbors() throws Exception { /* * Get the all the neighbors 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>> verticesWithAllNeighbors = graph.groupReduceOnEdges(new SelectNeighbors(), EdgeDirection.ALL); List<Tuple2<Long, Long>> result = verticesWithAllNeighbors.collect(); expectedResult = "1,2\n" + "1,3\n" + "1,5\n" + "2,1\n" + "2,3\n" + "3,1\n" + "3,2\n" + "3,4\n" + "3,5\n" + "4,3\n" + "4,5\n" + "5,1\n" + "5,3\n" + "5,4"; compareResultAsTuples(result, expectedResult); }