Java Code Examples for org.apache.flink.graph.Graph#fromCollection()
The following examples show how to use
org.apache.flink.graph.Graph#fromCollection() .
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: ScatterGatherConfigurationITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testInDegreesNotSet() throws Exception { /* * Test that if the degrees option is not set, then -1 is returned as a value for in-degree. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Vertex<Long, Long>> verticesWithDegrees = graph.runScatterGatherIteration( new DummyMessageFunction(), new UpdateFunctionInDegrees(), 2).getVertices(); List<Vertex<Long, Long>> result = verticesWithDegrees.collect(); expectedResult = "1,-1\n" + "2,-1\n" + "3,-1\n" + "4,-1\n" + "5,-1"; compareResultAsTuples(result, expectedResult); }
Example 2
Source File: SimplifyTest.java From flink with Apache License 2.0 | 6 votes |
@Before @Override public void setup() throws Exception{ super.setup(); Object[][] edges = new Object[][]{ new Object[]{0, 0}, new Object[]{0, 1}, new Object[]{0, 1}, new Object[]{0, 2}, new Object[]{0, 2}, new Object[]{1, 0}, new Object[]{2, 2}, }; List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>(); for (Object[] edge : edges) { edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance())); } graph = Graph.fromCollection(edgeList, env); }
Example 3
Source File: FromCollectionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFromCollectionEdgesWithInitialValue() throws Exception { /* * Test fromCollection(edges) with vertices initialised by a * function that takes the id and doubles it */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongEdges(), new InitVerticesMapper(), env); DataSet<Vertex<Long, Long>> data = graph.getVertices(); List<Vertex<Long, Long>> result = data.collect(); expectedResult = "1,2\n" + "2,4\n" + "3,6\n" + "4,8\n" + "5,10\n"; compareResultAsTuples(result, expectedResult); }
Example 4
Source File: TranslateTest.java From flink with Apache License 2.0 | 6 votes |
@Before public void setup() { ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment(); int count = 10; List<Vertex<LongValue, LongValue>> vertexList = new LinkedList<>(); List<Edge<LongValue, LongValue>> edgeList = new LinkedList<>(); for (long l = 0; l < count; l++) { LongValue lv0 = new LongValue(l); LongValue lv1 = new LongValue(l + 1); LongValue lv2 = new LongValue(l + 2); vertexList.add(new Vertex<>(lv0, lv1)); edgeList.add(new Edge<>(lv0, lv1, lv2)); } graph = Graph.fromCollection(vertexList, edgeList, env); }
Example 5
Source File: FromCollectionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFromCollectionEdgesNoInitialValue() throws Exception { /* * Test fromCollection(edges) with no initial value for the vertices */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, NullValue, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongEdges(), env); DataSet<Vertex<Long, NullValue>> data = graph.getVertices(); List<Vertex<Long, NullValue>> result = data.collect(); expectedResult = "1,(null)\n" + "2,(null)\n" + "3,(null)\n" + "4,(null)\n" + "5,(null)\n"; compareResultAsTuples(result, expectedResult); }
Example 6
Source File: ScatterGatherConfigurationITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testNumVerticesNotSet() throws Exception { /* * Test that if the number of vertices option is not set, -1 is returned as value. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Vertex<Long, Long>> verticesWithNumVertices = graph.runScatterGatherIteration(new DummyMessageFunction(), new UpdateFunctionNumVertices(), 2).getVertices(); List<Vertex<Long, Long>> result = verticesWithNumVertices.collect(); expectedResult = "1,-1\n" + "2,-1\n" + "3,-1\n" + "4,-1\n" + "5,-1"; compareResultAsTuples(result, expectedResult); }
Example 7
Source File: ScatterGatherConfigurationITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testInDegreesNotSet() throws Exception { /* * Test that if the degrees option is not set, then -1 is returned as a value for in-degree. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Vertex<Long, Long>> verticesWithDegrees = graph.runScatterGatherIteration( new DummyMessageFunction(), new UpdateFunctionInDegrees(), 2).getVertices(); List<Vertex<Long, Long>> result = verticesWithDegrees.collect(); expectedResult = "1,-1\n" + "2,-1\n" + "3,-1\n" + "4,-1\n" + "5,-1"; compareResultAsTuples(result, expectedResult); }
Example 8
Source File: FromCollectionITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testFromCollectionEdgesWithInitialValue() throws Exception { /* * Test fromCollection(edges) with vertices initialised by a * function that takes the id and doubles it */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongEdges(), new InitVerticesMapper(), env); DataSet<Vertex<Long, Long>> data = graph.getVertices(); List<Vertex<Long, Long>> result = data.collect(); expectedResult = "1,2\n" + "2,4\n" + "3,6\n" + "4,8\n" + "5,10\n"; compareResultAsTuples(result, expectedResult); }
Example 9
Source File: FromCollectionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFromCollectionVerticesEdges() throws Exception { /* * Test fromCollection(vertices, edges): */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Edge<Long, Long>> data = graph.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n"; compareResultAsTuples(result, expectedResult); }
Example 10
Source File: ScatterGatherConfigurationITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testOutDegreesNotSet() throws Exception { /* * Test that if the degrees option is not set, then -1 is returned as a value for out-degree. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Vertex<Long, Long>> verticesWithDegrees = graph.runScatterGatherIteration( new DummyMessageFunction(), new UpdateFunctionOutDegrees(), 2).getVertices(); List<Vertex<Long, Long>> result = verticesWithDegrees.collect(); expectedResult = "1,-1\n" + "2,-1\n" + "3,-1\n" + "4,-1\n" + "5,-1"; compareResultAsTuples(result, expectedResult); }
Example 11
Source File: SimplifyTest.java From flink with Apache License 2.0 | 6 votes |
@Before @Override public void setup() throws Exception{ super.setup(); Object[][] edges = new Object[][]{ new Object[]{0, 0}, new Object[]{0, 1}, new Object[]{0, 1}, new Object[]{0, 2}, new Object[]{0, 2}, new Object[]{1, 0}, new Object[]{2, 2}, }; List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>(); for (Object[] edge : edges) { edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance())); } graph = Graph.fromCollection(edgeList, env); }
Example 12
Source File: FromCollectionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFromCollectionVerticesEdges() throws Exception { /* * Test fromCollection(vertices, edges): */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); DataSet<Edge<Long, Long>> data = graph.getEdges(); List<Edge<Long, Long>> result = data.collect(); expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n"; compareResultAsTuples(result, expectedResult); }
Example 13
Source File: GraphOperationsITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public final void testIntersect() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>(); edges1.add(new Edge<>(1L, 3L, 12L)); edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output edges1.add(new Edge<>(1L, 3L, 14L)); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>(); edges2.add(new Edge<>(1L, 3L, 13L)); Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env); Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env); Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true); List<Vertex<Long, NullValue>> vertices = new ArrayList<>(); List<Edge<Long, Long>> edges = new ArrayList<>(); intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices)); intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges)); env.execute(); String expectedVertices = "1,(null)\n" + "3,(null)\n"; String expectedEdges = "1,3,13\n"; compareResultAsTuples(vertices, expectedVertices); compareResultAsTuples(edges, expectedEdges); }
Example 14
Source File: ScatterGatherConfigurationITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testOutDegreesSet() throws Exception { /* * Test that if the degrees are set, they can be accessed in every superstep * inside the update function and the value * is correctly computed for degrees in the scatter function. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env); // configure the iteration ScatterGatherConfiguration parameters = new ScatterGatherConfiguration(); parameters.setOptDegrees(true); DataSet<Vertex<Long, Long>> verticesWithDegrees = graph.runScatterGatherIteration( new DegreesMessageFunction(), new UpdateFunctionOutDegrees(), 5, parameters).getVertices(); List<Vertex<Long, Long>> result = verticesWithDegrees.collect(); expectedResult = "1,2\n" + "2,1\n" + "3,2\n" + "4,1\n" + "5,1"; compareResultAsTuples(result, expectedResult); }
Example 15
Source File: GraphOperationsITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public final void testIntersect() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>(); edges1.add(new Edge<>(1L, 3L, 12L)); edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output edges1.add(new Edge<>(1L, 3L, 14L)); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>(); edges2.add(new Edge<>(1L, 3L, 13L)); Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env); Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env); Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true); List<Vertex<Long, NullValue>> vertices = new ArrayList<>(); List<Edge<Long, Long>> edges = new ArrayList<>(); intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices)); intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges)); env.execute(); String expectedVertices = "1,(null)\n" + "3,(null)\n"; String expectedEdges = "1,3,13\n"; compareResultAsTuples(vertices, expectedVertices); compareResultAsTuples(edges, expectedEdges); }
Example 16
Source File: ScatterGatherConfigurationITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testDirectionALLAndDegrees() throws Exception { /* * Compute the number of neighbors in a vertex - centric manner, and verify that it is equal to * the sum: inDegree + outDegree. */ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); Graph<Long, Boolean, Long> graph = Graph.fromCollection(TestGraphUtils.getLongBooleanVertices(), TestGraphUtils.getLongLongEdges(), env); // configure the iteration ScatterGatherConfiguration parameters = new ScatterGatherConfiguration(); parameters.setOptDegrees(true); parameters.setDirection(EdgeDirection.ALL); DataSet<Vertex<Long, Boolean>> verticesWithNumNeighbors = graph.runScatterGatherIteration( new IdMessenger(), new VertexUpdateNumNeighbors(), 1, parameters).getVertices(); List<Vertex<Long, Boolean>> result = verticesWithNumNeighbors.collect(); expectedResult = "1,true\n" + "2,true\n" + "3,true\n" + "4,true\n" + "5,true"; compareResultAsTuples(result, expectedResult); }
Example 17
Source File: GraphOperationsITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public final void testIntersectWithPairs() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>(); edges1.add(new Edge<>(1L, 3L, 12L)); edges1.add(new Edge<>(1L, 3L, 13L)); edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 14L)); // output @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>(); edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 14L)); // output Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env); Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env); Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, false); List<Vertex<Long, NullValue>> vertices = new ArrayList<>(); List<Edge<Long, Long>> edges = new ArrayList<>(); intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices)); intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges)); env.execute(); String expectedVertices = "1,(null)\n" + "3,(null)\n"; String expectedEdges = "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14"; compareResultAsTuples(vertices, expectedVertices); compareResultAsTuples(edges, expectedEdges); }
Example 18
Source File: GraphOperationsITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public final void testIntersectWithPairs() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>(); edges1.add(new Edge<>(1L, 3L, 12L)); edges1.add(new Edge<>(1L, 3L, 13L)); edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 14L)); // output @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>(); edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 14L)); // output Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env); Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env); Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, false); List<Vertex<Long, NullValue>> vertices = new ArrayList<>(); List<Edge<Long, Long>> edges = new ArrayList<>(); intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices)); intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges)); env.execute(); String expectedVertices = "1,(null)\n" + "3,(null)\n"; String expectedEdges = "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14"; compareResultAsTuples(vertices, expectedVertices); compareResultAsTuples(edges, expectedEdges); }
Example 19
Source File: GraphOperationsITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public final void testIntersectWithPairs() throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>(); edges1.add(new Edge<>(1L, 3L, 12L)); edges1.add(new Edge<>(1L, 3L, 13L)); edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 13L)); // output edges1.add(new Edge<>(1L, 3L, 14L)); // output @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>(); edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 13L)); // output edges2.add(new Edge<>(1L, 3L, 14L)); // output Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env); Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env); Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, false); List<Vertex<Long, NullValue>> vertices = new ArrayList<>(); List<Edge<Long, Long>> edges = new ArrayList<>(); intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices)); intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges)); env.execute(); String expectedVertices = "1,(null)\n" + "3,(null)\n"; String expectedEdges = "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14"; compareResultAsTuples(vertices, expectedVertices); compareResultAsTuples(edges, expectedEdges); }
Example 20
Source File: AsmTestBase.java From flink with Apache License 2.0 | 4 votes |
@Before public void setup() throws Exception { env = ExecutionEnvironment.createCollectionsEnvironment(); env.getConfig().enableObjectReuse(); // a "fish" graph Object[][] edges = new Object[][]{ new Object[]{0, 1}, new Object[]{0, 2}, new Object[]{2, 1}, new Object[]{2, 3}, new Object[]{3, 1}, new Object[]{3, 4}, new Object[]{5, 3}, }; List<Edge<IntValue, NullValue>> directedEdgeList = new LinkedList<>(); for (Object[] edge : edges) { directedEdgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance())); } directedSimpleGraph = Graph.fromCollection(directedEdgeList, env); undirectedSimpleGraph = directedSimpleGraph .getUndirected(); // complete graph completeGraph = new CompleteGraph(env, completeGraphVertexCount) .generate(); // empty graph with vertices but no edges emptyGraphWithVertices = new EmptyGraph(env, emptyGraphVertexCount) .generate(); // empty graph with no vertices or edges emptyGraphWithoutVertices = new EmptyGraph(env, 0) .generate(); // star graph starGraph = new StarGraph(env, starGraphVertexCount) .generate(); }